private System.Diagnostics.EventLog Log;
private bool EventLoggerIsOk;
public void Initialize()
{
try
{
Log = new EventLog();
if (!EventLog.SourceExists("Source"))
{
EventLog.CreateEventSource("Source", "LogName");
}
Log.Source = "Source";
Log.Log = "LogName";
Log.ModifyOverflowPolicy(OverflowAction.OverwriteA sNeeded, 5);
EventLoggerIsOk = true;
}
catch
{
EventLoggerIsOk = false;
}
}
public System.Diagnostics.EventLogEntryCollection Events
{
get
{
return (Log.Entries);
}
}
private string PrepareMessage(string Message)
{
// Do what ever string function
return (Message);
}
public void LogMessage(string Message)
{
if (EventLoggerIsOk)
{
this.Log.WriteEntry(PrepareMessage(Message),
System.Diagnostics.EventLogEntryType.Information);
}
}
public void LogError(string Message)
{
if (EventLoggerIsOk)
{
this.Log.WriteEntry(PrepareMessage(Message),
System.Diagnostics.EventLogEntryType.Error);
}
}
public void LogWarning(string Message)
{
if (EventLoggerIsOk)
{
this.Log.WriteEntry(PrepareMessage(Message),
System.Diagnostics.EventLogEntryType.Warning);
}
}
"Abra" <no****@devdex.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,
I would like to be able from my C# .NET application to send
(programatically) 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 ***