EventLog is a good place to write your applications log. Here is an example to show how to do this:
If ( !EventLog.SourceExists("TestCategory"))
EventLog evtLog = new EventLog();
evtLog.Source = "TestCategory";
evtLog.WriteEntry("This is a test log.",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 type EventLog. we set the given category. 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 or the user of the application pool must have the necessary permissions:
We have to set the following permissions:
- Query Value
- Set Value
- Create Subkey
- Read Subkey
After setting these permissions it should be possible to create eventlog enteries through ASP.NET
This site uses Akismet to reduce spam. Learn how your comment data is processed.