The Eventlog is a good place to leave some log messages. Here is an example how to do this:
if (!EventLog.SourceExists("TestCategory"))
EventLog.CreateEventSource("TestCategory", "TestLog");
EventLog evtLog = new EventLog();
evtLog.Source = "TestCategory";
evtLog.WriteEntry("This is a test", EventLogEntryType.Information);
First of all there is a check if the category exists. If not it will be created. Then we create an object of the typ EventLog. We set the given catetory. After that you can use the method WriteEntry to write a new entry to the eventlog.
If you want to use this with ASP.NET you have to do some additional steps. There is a registry key where the ASPNET-User and/or the user of the application pool must have the necessary rights:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog
You have to set the following rights:
- Query Value
- Set Value
- Create Subkey
- Read Subkey
- Notifications
- Read
After setting this rights it should be possible to create eventlog entries using ASP.NET
9d2c8296-20be-4ea0-a0f8-7dc2fb4ac6f7|1|5.0
c#, eventlog