473,493 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

EventLog class and Event Viewer

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
Jul 21 '05 #1
2 5233
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

Jul 21 '05 #2
Thanks Deepak.

However that is not exactly what I was trying to achieve. I was hoping to mark the event log as "Over write as needed", as is done through the GUI checkbox.

I believe this causes the oldest errors to be overwritten first, rather than simply blowing the whole log away when it becomes full.

Any suggestions on how to do that?

thanks
Robb
Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
305
by: WalterB | last post by:
I am using the .net eventlog component to view eventlog entries on a local machine. For some reason, the eventID that the eventlog component is retrieving is different than the eventID that is...
1
1401
by: Franky | last post by:
How to create a ".evt" like the Evnt viewer by code. I whan to save in a file the current Evenlog. I know a can do public static void SaveLog(){ System.Diagnostics.EventLog oLog = new...
3
1485
by: bas jaburg | last post by:
Hi, I am using the Microsoft Application BuildingBolock (Freudian slip, hahaha) Exception Management and am using a CustomPublisher. This goes fine and it write's stuff the Windows EventLog. ...
2
388
by: rgilmore | last post by:
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...
7
7434
by: Rob R. Ainscough | last post by:
I'm having difficulty writing anything to the web servers event log from my web app located on that server. Putting this in my web apps web.config did NOT help - immediate causes and error in my...
0
1496
by: sk.rasheedfarhan | last post by:
Hi all, According to my project requirement I have to write the NT Event information of SQL Server into EventLog viewer. For more clear I want to write the following information into...
7
2570
by: Grant Schenck | last post by:
How can I eliminate this URL link which is automatically appended to what I write to the event log using EventLog.WriteEntry()? "For more information, see Help and Support Center at...
0
1032
by: Mike | last post by:
I am using the eventlog class to read the event logs. This works ok except that the message is not returned correctly for most events. For example, suppose there is an event in the event log with...
2
1159
by: Dennis | last post by:
I have a service with the following startup code... When I start the service I see a new entry under... Computer Management(local) System Tools Event Viewer Application MyServiceLog ...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7367
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5453
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1400
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.