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
Here is an example of a custom Event logger for .Net 3.5 and 4.0.
Log4Net is also a great tool for this, in my case I was building a lib and the client's calling program did not have log4net..
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.