Eventlog Installing

  • Thread starter Thread starter timb
  • Start date Start date
T

timb

Hi,
am creating a windows service using c# and would like it to create a
new eventlog logtype and add it to the eventlog viewer so that i can log all
messages relating to this application to this specific log. Does anyone
have any code for this which works as i have tried the examples but am
unable to find the log in the eventlogviewer or anywhere on the hard drive
afterwards.

Thanks in advance
TimB
 
hi timb,
you can try this one, it will reflect on the application log.

using(EventLog oEL = new EventLog())
{
oEL.Source = "MyApps";
using(EventLogTraceListener oELT = new EventLogTraceListener())
{
oELT.EventLog = oEL;

oEL.WriteEntry("My EventLog Entry",EventLogEntryType.Information);
oELT.Flush();
}
}

EventLog and EventLogTraceListener is under System.Diagnostics.

hope this helps,
 
Hi Gani,
i am able to write to the application log however i thought i
was possible to create a new log type which was displayed in the
evertviewer. i.e. different to application,system,security etc


thanks in advance
TimB
 
Hi,
You can check my article at code project (sample source is in VB.NET)
http://www.codeproject.com/dotnet/evtvwr.asp

This talks about creating and using custom event logs, sources and
categories.

BTW, this is a simple code snippet to just create a new source and a new
log:
objEventLog.CreateEventSource("MySource","MyLog")
 
Hi,
Have tried this code and similar c# code from the help file and it works
no problems unless i try and run it from a windows service. I have tried
setting the service to run under an account which has administrator rights
on the local machine but this doesnt seem to help. Any ideas?
 
Back
Top