Hi Robb,
You can achieve this by catching an exception of type
System.ComponentModel.Win32Exception
in the catch block you can then clear the event log.
Below is the code that will achieve this.
static void WriteToEventLog()
{
Console.WriteLine("Writing to the Event Log");
if(!EventLog.SourceExists("DotNetConsoleApp"))
{
EventLog.CreateEventSource("DotNetConsoleApp","App lication");
}
try
{
EventLog el = new EventLog();
el.Source = "Application";
el.WriteEntry("Writing to event log",EventLogEntryType.Information);
}
catch(System.ComponentModel.Win32Exception ex)
{
if (ex.Message == "The event log file is full")
{
EventLog el = new EventLog();
el.Source = "Application";
el.Clear();
}
}
}
Regards
--
Deepak
#*#*#*#*#*#*#*#*#*#
I code therefore I am
"rgilmore" <an*******@discussions.microsoft.com> wrote in message
news:7F**********************************@microsof t.com...
Our app uses the EventLog class to write errors to the event log.
Sometimes the app runs unattended for days, and if errors are occurring, the
event log can fill up, causing the app to have no way of reporting further
errors. The user needs to manually clear the event log in this case.
To prevent this, we would like to specify the "Overwrite as needed" option
on our event log to make it circular. This option is available as a
checkbox on the properties page of the log itself when viewed through the
event viewer.
I don't see any methods on the EventLog class for setting this property.
Is there a way to set this programatically?
--thanks, Robb