开发者

c# Event log Full or Not

How to now whether the Application Eventlog is full o开发者_JAVA技巧r Not.there is any option to clear all the events in application event log. My code is

 EventLog log = new EventLog("Application");
            log.Source = "Voting Editor Tool";
            log.WriteEntry(ex.Message);


You can try catch

try
{
    EventLog log = new EventLog("Application");
    log.Source = "Voting Editor Tool";
    log.WriteEntry(ex.Message);
}
catch (Win32Exception w32ex)
{
    // full
}

To clear the event log use

log.clear();

Quote from the docs.

Event logs are set with a maximum size that determines how many entries they can contain. When an event log is full, it stops recording new event information or begins to overwrite earlier entries. If event recording stops, you can use this method to clear the log of existing entries and allow it to start recording events again. You must have administrator permissions to the computer on which the log resides to clear event log entries.


you can go to the event viewer and specify the log is circular so old entries will be eaten by new ones as needed.

I am sure you could specify this when you run your installation script which creates the new event log for your application.


To avoid this situation we need to set the “OverflowAction” Action Property to either “OverwriteAsNeeded” or “OverwriteOlder” as shown below:

enter code here

EventLog eventLog = new EventLog();                    
eventLog.Source = "ViewImagePDF";
if (eventLog.OverflowAction != OverflowAction.OverwriteAsNeeded)
{
    eventLog.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, 1);
}
eventLog.WriteEntry("This is sample information", EventLogEntryType.Information); 

Please follow the LINK Thanks, Siddi.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜