home *** CD-ROM | disk | FTP | other *** search
-
- <!-- #include virtual="/quickstart/howto/include/header.inc" -->
-
- <h4>How Do I...Monitor an event log?</h4>
-
- <div class="indent" style="width:660"><font face="Tahoma" size="1">
-
- <p>Event
- logging provides a standard, centralized way for you to have your applications
- record important software and hardware events. Windows supplies a standard user
- interface for viewing the logs (Event Log Viewer). Using the NGWS runtime's EventLog
- component, you can easily connect to existing event logs on both local and
- remote computers and receive event notifications when a new entry is written to
- the log.</p>
-
- <p>This
- sample illustrates how to monitor an event log for new entries being written.
- It's a small console application that can be run from a command prompt. The
- application takes two command line arguments. The first argument is the name of
- the log that you want to monitor. The second is optional and allows you to
- specify the machine name of the server on which the log resides.</p>
-
- <p>Try running the sample as follows:</p>
-
- </font><font face="Courier New" color="Blue" size="1"><blockquote>
- > LogMonitor.exe Application
- </blockquote></font><font face="Tahoma" size="1">
-
- <p>Now,
- run the LogWrite.exe sample and write a new entry to the application log. You
- will see that the LogMonitor is being notified about the new entry being
- written.</p>
-
- <p>In its simplest form, monitoring an event log involves:</p>
-
- <ol>
- <li>Instantiating an EventLog component and pointing it to a appropriate event log:
-
- </font><font face="Courier New" color="Blue" size="1"><p>
- EventLog aLog = new EventLog();<br>
- aLog.Log = log;<br>
- aLog.MachineName = machine;
- </p></font><font face="Tahoma" size="1">
-
- <li>Adding an event handler:
-
- </font><font face="Courier New" color="Blue" size="1"><p>
- aLog.AddOnEntryWritten(new EventLogEventHandler(OnEntryWritten));
- </p></font><font face="Tahoma" size="1">
-
- <li>Handling the event notification in your event handler:
-
- </font><font face="Courier New" color="Blue" size="1"><p>
- public static void OnEntryWritten(Object source, EventLogEvent e) {<br>
- Console.WriteLine("Written: " + e.Entry.Message);<br>
- }
- </p></font><font face="Tahoma" size="1">
-
- </ol>
-
- <p>Have a great time EventLog'ing!
- </font></div>
-
- <h4>Example</h4>
-
- <p>
- <div class="indent">
- <a target="_blank" href="/quickstart/howto/samples/Services/EventLog/LogMonitor">
- <img style="border-color:black" border=1 src="/quickstart/images/genicon.gif"><br>
- </a>
- <div class="caption">LogMonitor.exe</div><br>
- [<a target="_blank" href="/quickstart/howto/samples/Services/EventLog/LogMonitor">View Sample</a>] |
- [<a target="_blank" href="/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/Services/EventLog/LogMonitor/LogMonitor.src">View Source</a>]<p>
- </div>
-
- <h4>Source Code</h4>
-
- <div class="code">
- <xmp>
- <!-- #include virtual="/quickstart/howto/samples/Services/EventLog/LogMonitor/LogMonitor.cs" -->
- </xmp>
- </div>
-
- <!-- #include virtual="/quickstart/howto/include/footer.inc" -->