How do I programmatically check for/create a custom event log to be viewed in Windows XP/2003 event viewer?
Right now I can create entries in the 'Application' log but want to have custom logs for my various applications.
I am using C# - .NET Framework 3.5
The System.Diagnostics.EventLog
class in the framework has a CreateEventSource
method...
EventLog.CreateEventSource(source, logName);
Be aware that to create a new eventLog (or eventLog Source) requires a higher level of authority (WIndows Access Control List (ACL) permissions), than does simply writing to the log, and normally, this access level is not available to most applications... So you will need to make sure your deployment process or deployment msi does the event log/source creation at that time... when the process installing the app should have sufficient permissions.
You need to create a custom event log, as described here. If you are using log4net for logging (recommended), you can configure an EventLogAppender
as in the following example:
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
<applicationName value="MyApp" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level %logger - %message%newline" />
</layout>
</appender>
You need to specify the Log property of the EventLog object.
Documentation can be found here:
http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.log.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With