home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / QuickStart / howto / doc / logmonitor.aspx < prev    next >
Encoding:
Text File  |  2000-06-08  |  3.0 KB  |  84 lines

  1.  
  2. <!-- #include virtual="/quickstart/howto/include/header.inc" -->
  3.  
  4. <h4>How Do I...Monitor an event log?</h4>
  5.  
  6. <div class="indent" style="width:660"><font face="Tahoma" size="1">
  7.  
  8. <p>Event
  9. logging provides a standard, centralized way for you to have your applications
  10. record important software and hardware events. Windows supplies a standard user
  11. interface for viewing the logs (Event Log Viewer). Using the NGWS runtime's EventLog
  12. component, you can easily connect to existing event logs on both local and
  13. remote computers and receive event notifications when a new entry is written to
  14. the log.</p>
  15.  
  16. <p>This
  17. sample illustrates how to monitor an event log for new entries being written.
  18. It's a small console application that can be run from a command prompt. The
  19. application takes two command line arguments. The first argument is the name of
  20. the log that you want to monitor. The second is optional and allows you to
  21. specify the machine name of the server on which the log resides.</p>
  22.  
  23. <p>Try running the sample as follows:</p>
  24.  
  25. </font><font face="Courier New" color="Blue" size="1"><blockquote>
  26.     > LogMonitor.exe Application
  27. </blockquote></font><font face="Tahoma" size="1">
  28.  
  29. <p>Now,
  30. run the LogWrite.exe sample and write a new entry to the application log. You
  31. will see that the LogMonitor is being notified about the new entry being
  32. written.</p>
  33.  
  34. <p>In its simplest form, monitoring an event log involves:</p>
  35.  
  36. <ol>
  37. <li>Instantiating an EventLog component and pointing it to a appropriate event log:
  38.  
  39.     </font><font face="Courier New" color="Blue" size="1"><p>
  40.         EventLog aLog = new EventLog();<br>
  41.         aLog.Log = log;<br>
  42.         aLog.MachineName = machine;
  43.     </p></font><font face="Tahoma" size="1">
  44.  
  45. <li>Adding an event handler:
  46.  
  47.     </font><font face="Courier New" color="Blue" size="1"><p>
  48.         aLog.AddOnEntryWritten(new EventLogEventHandler(OnEntryWritten));
  49.     </p></font><font face="Tahoma" size="1">
  50.  
  51. <li>Handling the event notification in your event handler:
  52.  
  53.     </font><font face="Courier New" color="Blue" size="1"><p>
  54.         public static void OnEntryWritten(Object source, EventLogEvent e) {<br>
  55.             Console.WriteLine("Written: " + e.Entry.Message);<br>
  56.         }
  57.     </p></font><font face="Tahoma" size="1">
  58.  
  59. </ol>
  60.  
  61. <p>Have a great time EventLog'ing!
  62. </font></div>
  63.  
  64. <h4>Example</h4>
  65.  
  66. <p>
  67. <div class="indent">
  68. <a target="_blank" href="/quickstart/howto/samples/Services/EventLog/LogMonitor">
  69. <img style="border-color:black" border=1 src="/quickstart/images/genicon.gif"><br>
  70. </a>
  71. <div class="caption">LogMonitor.exe</div><br>
  72. [<a target="_blank" href="/quickstart/howto/samples/Services/EventLog/LogMonitor">View Sample</a>] | 
  73. [<a target="_blank" href="/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/Services/EventLog/LogMonitor/LogMonitor.src">View Source</a>]<p>
  74. </div>
  75.  
  76. <h4>Source Code</h4>
  77.  
  78. <div class="code">
  79. <xmp>
  80. <!-- #include virtual="/quickstart/howto/samples/Services/EventLog/LogMonitor/LogMonitor.cs" -->
  81. </xmp>
  82. </div>
  83.  
  84. <!-- #include virtual="/quickstart/howto/include/footer.inc" -->