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

  1.  
  2. <!-- #include virtual="/quickstart/howto/include/header.inc" -->
  3.  
  4. <h4>How Do I...Read from an event log?</h4>
  5.  
  6. <div class="indent" style="width:660"><font face="Tahoma" size="1">
  7.  
  8. <p>Event logging provides a standard, centralized way for you
  9. to have your applications record important software and hardware events. Windows
  10. supplies a standard user interface for viewing the logs (Event Log Viewer).
  11. Using the NGWS runtime's EventLog component, you can easily connect to existing event
  12. logs on both local and remote computers and read entries from these logs programmatically.
  13.  
  14. <p>This sample illustrates how to enumerate entries in an event
  15. log. ItÆs a small console application that can be run from a command prompt.
  16. The application takes two command line arguments. The first argument is the name
  17. of the log that you want to enumerate. The second is optional and allows you to
  18. specify the machine name of the server on which the log resides.</p>
  19.  
  20. <p>Try running the sample as follows:</p>
  21.  
  22. </font><font face="Courier New" color="Blue" size="1"><blockquote>
  23.     > LogInfo.exe Application
  24. </blockquote></font><font face="Tahoma" size="1">
  25.  
  26. <p>The
  27. sample will list all the entries from the Application log. You can try the same
  28. with the System, Security, and any other logs residing on your machine.</p>
  29.  
  30. <p>In its simplest form, writing to an event log involves:</p>
  31.  
  32. <ol>
  33. <li>Instantiating an EventLog component and pointing it to an appropriate event log:
  34.  
  35.     </font><font face="Courier New" color="Blue" size="1"><p>
  36.         EventLog aLog = new EventLog();<br>
  37.         aLog.Log = log;<br>
  38.         aLog.MachineName = machine;
  39.     </p></font><font face="Tahoma" size="1">
  40.  
  41. <li>Enumerating through the Entries collection of the EventLog instance:
  42.  
  43.     </font><font face="Courier New" color="Blue" size="1"><p>
  44.         foreach (EventLogEntry entry in aLog.Entries)<br>
  45.         {<br>
  46.             Console.WriteLine("\tEntry: " + entry.Message);<br>
  47.         }
  48.     </p></font><font face="Tahoma" size="1">
  49.  
  50. </ol>
  51.  
  52. <p>Have a great time EventLog'ing! 
  53. </font></div>
  54.  
  55. <h4>Example</h4>
  56.  
  57. <p>
  58. <div class="indent">
  59. <a target="_blank" href="/quickstart/howto/samples/Services/EventLog/LogInfo">
  60. <img style="border-color:black" border=1 src="/quickstart/images/genicon.gif"><br>
  61. </a>
  62. <div class="caption">LogInfo.exe</div><br>
  63. [<a target="_blank" href="/quickstart/howto/samples/Services/EventLog/LogInfo">View Sample</a>] | 
  64. [<a target="_blank" href="/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/Services/EventLog/LogInfo/LogInfo.src">View Source</a>]<p>
  65. </div>
  66.  
  67. <h4>Source Code</h4>
  68.  
  69. <div class="code">
  70. <xmp>
  71. <!-- #include virtual="/quickstart/howto/samples/Services/EventLog/LogInfo/LogInfo.cs" -->
  72. </xmp>
  73. </div>
  74.  
  75. <!-- #include virtual="/quickstart/howto/include/footer.inc" -->