private System.Diagnost ics.EventLog Log;
private bool EventLoggerIsOk ;
public void Initialize()
{
try
{
Log = new EventLog();
if (!EventLog.Sour ceExists("Sourc e"))
{
EventLog.Create EventSource("So urce", "LogName");
}
Log.Source = "Source";
Log.Log = "LogName";
Log.ModifyOverf lowPolicy(Overf lowAction.Overw riteAsNeeded, 5);
EventLoggerIsOk = true;
}
catch
{
EventLoggerIsOk = false;
}
}
public System.Diagnost ics.EventLogEnt ryCollection Events
{
get
{
return (Log.Entries);
}
}
private string PrepareMessage( string Message)
{
// Do what ever string function
return (Message);
}
public void LogMessage(stri ng Message)
{
if (EventLoggerIsO k)
{
this.Log.WriteE ntry(PrepareMes sage(Message),
System.Diagnost ics.EventLogEnt ryType.Informat ion);
}
}
public void LogError(string Message)
{
if (EventLoggerIsO k)
{
this.Log.WriteE ntry(PrepareMes sage(Message),
System.Diagnost ics.EventLogEnt ryType.Error);
}
}
public void LogWarning(stri ng Message)
{
if (EventLoggerIsO k)
{
this.Log.WriteE ntry(PrepareMes sage(Message),
System.Diagnost ics.EventLogEnt ryType.Warning) ;
}
}
"Abra" <no****@devdex. com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi,
I would like to be able from my C# .NET application to send
(programaticall y) different debug messages to an own directory in the
standard Windows Event Viewer. Which .NET classes provide access to the
Windows Event Viewer ? Is it possible to configure it to automatically
log the messages into files after a given amount of records ? Is it
possible to have the message time-stamps in milliseconds ?
Some code sample of using such .NET classes would be appreciated.
Thanks in advance for your help.
Regards,
Abra
*** Sent via Developersdex http://www.developersdex.com ***