home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / cpref.chm / html / frlrfsystemdiagnosticseventlogclasssourcetopic.htm < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  7.6 KB  |  121 lines

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
  2. <HTML DIR=LTR>
  3. <HEAD>
  4. <META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">
  5. <TITLE>EventLog.Source</TITLE>
  6. <SCRIPT src="vs70link.js"></SCRIPT>
  7. <SCRIPT src="vs70.js"></SCRIPT>
  8. </HEAD>
  9. <body topmargin="0" id="bodyID" class = "dtBODY">
  10. <object id="obj_cook" classid="clsid:59CC0C20-679B-11D2-88BD-0800361A1803" style="display:none;"></object>
  11.  
  12. <div id="nsbanner">
  13. <div id="bannerrow1">
  14. <TABLE CLASS="bannerparthead" CELLSPACING=0>
  15. <TR ID="hdr">
  16. <TD CLASS="runninghead" nowrap>NGWS SDK Documentation</TD>
  17. <TD CLASS="product" nowrap> </TD>
  18. </TR>
  19. </TABLE>
  20. </div>
  21. </div>
  22. <DIV id="nstext" valign="bottom">
  23. <br>
  24. <font color=ff0000 size="1"><i>This is preliminary documentation and subject to change.</i></font>
  25. <br>
  26. <font size="1"><i>To comment on this topic, please send us email at <a href="mailto:ngwssdk@microsoft.com">ngwssdk@microsoft.com</a>. Thanks!</i></font>
  27. <br>
  28. <br>
  29.  
  30. <H1 class="dtH1"><A NAME="frlrfsystemdiagnosticseventlogclasssourcetopic"></A>EventLog.Source</H1>
  31.  
  32. <P>Gets or sets the application name (source name) to register and use when writing to the event log.</P>
  33.  
  34. <PRE class="syntax"><SPAN class="lang">[Visual Basic]
  35. </SPAN><B>Overridable Public Property Source As String
  36. </B><SPAN class="lang">[C#]
  37. </SPAN><B>public string Source {virtual get; virtual set;}
  38. </B><SPAN class="lang">[C++]
  39. </SPAN><B>public: __property virtual String* get_Source();
  40. public: __property virtual void set_Source(String*);
  41. </B><SPAN class="lang">[JScript]
  42. </SPAN><B>public function get Source() : String;
  43. public function set Source(String);</B></PRE>
  44.  
  45. <H4 class="dtH4">Property Value</H4>
  46.  
  47. <P>The application name registered with the event log as a valid source of entries. The default is an empty string ("").</P>
  48.  
  49. <H4 class="dtH4">Remarks</H4>
  50.  
  51. <P>The event <B>Source</B> is the name of the software that logs the event. It is often the name of the application, or the name of a subcomponent of the application, if the application is large. Applications and services should write to the Application log or a custom log. Device drivers should add their names to the System log.</P>
  52.  
  53. <P>If you write to an event log, you must specify or create an event <B>Source</B>. The <B>Source</B>, which can only be used to write to a single log at a time, registers your application with the event log as a valid source of entries. The <B>Source</B> can be any random string, but the name cannot be used by other sources on the computer; an attempt to create a duplicated <B>Source</B> value will throw an exception. However, a single event log can have many different sources writing to it.</P>
  54.  
  55. <BLOCKQUOTE class="dtBlock">
  56. <b class="le">Note</b>    <B>Source</B> names cannot be  hierarchical. That is, you cannot use the backslash "\" character.</BLOCKQUOTE>
  57.  
  58. <P>It is not necessary to specify a <B>Source</B> when only reading from a log. You can specify only the <A href="frlrfsystemdiagnosticseventlogclasslogtopic.htm">Log</A> name and <A href="frlrfsystemdiagnosticseventlogclassmachinenametopic.htm">MachineName</A> (server computer name) for the <B>EventLog</B> instance. In either case, the <A href="frlrfsystemdiagnosticseventlogclassentriestopic.htm">Entries</A> member is automatically populated  with the event log's list of entries. You can select the appropriate index for an item in this list to read individual entries.</P>
  59.  
  60. <BLOCKQUOTE class="dtBlock">
  61. <b class="le">Note</b>   You are not explicitly required to specify the <A href="frlrfsystemdiagnosticseventlogclassmachinenametopic.htm">MachineName</A> if you are connecting to a log by specifying a <A href="frlrfsystemdiagnosticseventlogclasslogtopic.htm">Log</A>/ <B>MachineName</B> pair. If you do not specify the <B>MachineName</B>, the local computer (".") is assumed.</BLOCKQUOTE>
  62.  
  63. <P>The <B>Source</B> value can be an empty string, particularly if you are only reading from the event log. If the <B>Source</B> value changes, the event log to which it is registered is closed and all event handles are released.</P>
  64.  
  65. <P>If you do not specify a log name when calling <A href="frlrfsystemdiagnosticseventlogclasscreateeventsourcetopic.htm">CreateEventSource</A>, your source will be registered to  the Application log. If you specify the name of a log that doesn't exist, the system creates a custom event log for you and registers the <B>Source</B> to that log.</P>
  66.  
  67. <P>When you write a log entry using <A href="frlrfsystemdiagnosticseventlogclasswriteentrytopic.htm">WriteEntry</A>, the system uses the source you identified to find the appropriate log in which to place your entry.</P>
  68.  
  69. <BLOCKQUOTE class="dtBlock">
  70. <b class="le">Note</b>   If you try to call <A href="frlrfsystemdiagnosticseventlogclasswriteentrytopic.htm">WriteEntry</A> without first having registered the value specified by your <B>EventLog</B> instance's <B>Source</B> parameter as a valid source, Visual Studio automatically registers your component, using the <B>Source</B> value as the source string.</BLOCKQUOTE>
  71.  
  72. <H4 class="dtH4">Example <SPAN class="lang">[Visual Basic]</SPAN></H4>
  73.  
  74. <P>The following example connects to an event log, "myNewLog", on the local computer. If the source "myNewSource" does not already exist on the computer, it is created. Then, an entry is written to the <A href="frlrfsystemdiagnosticseventlogclasslogtopic.htm">Log</A>.</P>
  75.  
  76. <P>Note that the way to create a new event log is through the static (in Visual Basic <B>Shared</B>) member <A href="frlrfsystemdiagnosticseventlogclasscreateeventsourcetopic.htm">CreateEventSource</A>, which creates a <B>Source</B> and registers it to the <B>Log</B> at the time the log is created. Because this is a static (<B>Shared</B>) member of <B>EventLog</B>, it should be called on the class itself rather than on an instance of the class.</P>
  77.  
  78. <P>Import the System.Diagnostics namespace for this example.</P>
  79.  
  80. <P><SPAN class="lang">[Visual Basic]</SPAN></P>
  81.  
  82. <PRE class="code">Private Sub ConnectToEventLog()
  83.     'Declare a new event log and event log entry.
  84.     Dim evtLog As EventLog
  85.     'Used in a for loop iterating through entries()
  86.     Dim i As Integer
  87.  
  88.     'Instantiate a new event log.
  89.     evtLog = New EventLog
  90.  
  91.     'Otherwise, create a new source and log.
  92.     If Not EventLog.SourceExists("myNewSource") Then
  93.         'If MyNewLog does not exist, it will be created
  94.         EventLog.CreateEventSource("myNewSource", "myNewLog")
  95.     End If
  96.     
  97.     'Connect the source to the event instance.
  98.     evtLog.Source = "myNewSource"
  99.     
  100.     'Write an entry to the event log.
  101.     evtLog.WriteEntry("My entry.")
  102. End Sub</PRE>
  103.  
  104. <H4 class="dtH4">See Also</H4>
  105.  
  106. <P><A href="frlrfsystemdiagnosticseventlogclasstopic.htm">EventLog Class</A> | <A href="frlrfsystemdiagnosticseventlogmemberstopic.htm">EventLog Members</A> | <A href="frlrfsystemdiagnostics.htm">System.Diagnostics Namespace</A> | <A href="frlrfsystemdiagnosticseventlogclasslogtopic.htm">Log</A> | <A href="frlrfsystemdiagnosticseventlogclassmachinenametopic.htm">MachineName</A> | <A href="frlrfsystemdiagnosticseventlogclasscreateeventsourcetopic.htm">CreateEventSource</A> | <A href="frlrfsystemdiagnosticseventlogclassdeleteeventsourcetopic.htm">DeleteEventSource</A> | <A href="frlrfsystemdiagnosticseventlogclasssourceexiststopic.htm">SourceExists</A></P>
  107. <div class="footer">
  108. <p>
  109. <center><font color="navy" size="1">Build number 1812.</font></center>
  110. <p>
  111. </div>
  112. <div class="footer">
  113. <br>
  114. <center><font size="1"><a href="copybeta_nonconfidential.htm">© 2000 Microsoft Corporation. All rights reserved.</a></font></center>
  115. <br>
  116. </div>
  117. </div>
  118.  
  119. </BODY>
  120. </HTML>
  121.