c# - Custom value for the Event Log source property for ASP.NET errors -


By default, ASP.NET system records all unqualified exceptions in the event log. I am aware of the fact that one should have proper logging facility, but it is better than anything else and it works well as a temporary solution.

I want to be able to filter efficiently events in log I have learned that, when entering during programming, you can set a custom value for the source column in the event log:

  EventLog eventLog = new EventLog ("app"); EventLog.Source = "My Custom Name"; EventLog.WriteEntry ("Some error details ...", EventLogEntryType.Error);  

However, ASP.Net sets this value according to "ASP.NET", according to its version. I did a brief investigation of web.config's documentation, but did not get a clear place to replace it. I wonder if it can be changed at all.

Your best bet is to use the source source, but at the time installed in the installer, Under), use the installer class, for example:

 using the system; Using System.Collections; Using System.Collections.Generic; Using System.ComponentModel; Using System.configuration.Install; Using System.Diagnostics; Namespace InstallerClasses {[RunInstaller (true)] Public Partial Class EventLog: Installer {Private EventLogInstaller eventLogInstaller; /////// MyApp /// creates event logs for public event logs () {InitializeComponent (); // Create an example of an EventLogInstaller EventLogInstaller = New Event Logger Installer (); // Set the source name of the event log EventLogInstaller.Source = "MySource"; // Set the event log that writes entries to the source. EventLogInstaller.log = "app"; // Add myEventLogInstaller to the installer archive. Installers.Add (eventLogInstaller); }}} 

and make sure it is run as a custom action in your installer.


Comments