<font color=ff0000 size="1"><i>This is preliminary documentation and subject to change.</i></font>
<br>
<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>
<P>The application name registered with the event log as a valid source of entries. The default is an empty string ("").</P>
<H4 class="dtH4">Remarks</H4>
<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>
<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>
<BLOCKQUOTE class="dtBlock">
<b class="le">Note</b> <B>Source</B> names cannot be hierarchical. That is, you cannot use the backslash "\" character.</BLOCKQUOTE>
<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>
<BLOCKQUOTE class="dtBlock">
<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>
<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>
<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>
<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>
<BLOCKQUOTE class="dtBlock">
<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>
<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>
<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>
<P>Import the System.Diagnostics namespace for this example.</P>