locked
EventLog.EntryWritten and Event Log Overwrite as Needed RRS feed

  • Question

  • I'm having an issue watching event logs on computers.  I catch the events fine with the simple code from here: http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.entrywritten.aspx

    using System;
    using System.Diagnostics;
    using System.Threading;
    
    class MySample{
    
      // This member is used to wait for events.
      static AutoResetEvent signal;
    
      public static void Main(){
    
        signal = new AutoResetEvent(false);
        EventLog myNewLog = new EventLog("Application", ".", "testEventLogEvent");         
    
        myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten);
        myNewLog.EnableRaisingEvents = true;
        myNewLog.WriteEntry("Test message", EventLogEntryType.Information);
    	  signal.WaitOne();    
    
      }    
    
      public static void MyOnEntryWritten(object source, EntryWrittenEventArgs e){
        Console.WriteLine("In event handler");
        //signal.Set();
      }
    }
    

    The issue is that when the event log on the computer is set to overwrite as needed, it seems to "lose" my EventLog object in the EntryWritten handler.  EntryWrittenEventArgs ends up without any usable data.  This is repeatable on any computer.

    Is there some way to know when the event log is overwritting itself?  

    Thanks.


    If everyone is thinking alike, then somebody isn't thinking.
    • Moved by Leo Liu - MSFT Wednesday, March 30, 2011 2:05 AM Off-topic (From:Visual C# General)
    Wednesday, March 23, 2011 4:57 PM

Answers

  • If it is proved to be an issue, you can submit your suggestion to Microsoft Connect feedback portal http://connect.microsoft.com, Microsoft engineers will evaluate it seriously. If this issue is urgent, please contact support at http://support.microsoft.com. Thanks.
    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, March 30, 2011 2:04 AM
  • This was moved out of the VC# forum.

    You can ask this at www.answers.micorosft.com or in another forum.

    Or I can move it into a specific MSDN/TechNet forum if you'd like.

    This is regarding your event log code:

    using System;
    using System.Diagnostics;
    using System.Threading;
    
    class MySample{
    
      static AutoResetEvent signal;
    
      public static void Main(){
    
        signal = new AutoResetEvent(false);
        EventLog myNewLog = new EventLog("Application", ".", "testEventLogEvent");         
    
        myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten);
        myNewLog.EnableRaisingEvents = true;
        myNewLog.WriteEntry("Test message", EventLogEntryType.Information);
    	  signal.WaitOne();    
    
    

     


    Ed Price a.k.a User Ed, Microsoft Experience Program Manager (Blog, Twitter, Wiki)
    Saturday, December 31, 2011 12:29 AM

All replies