This documentation is archived and is not being maintained.

EventSourceCreationData.Source Property

Note: This property is new in the .NET Framework version 2.0.

Gets or sets the name to register with the event log as an event source.

Namespace: System.Diagnostics
Assembly: System (in system.dll)

public string Source { get; set; }
/** @property */
public String get_Source ()

/** @property */
public void set_Source (String value)

public function get Source () : String

public function set Source (value : String)

Property Value

The name to register with the event log as a source of entries. The default is an empty string ("").

The source name is often the name of the application, or the name of a component within a large application. The EventLog.CreateEventSource(EventSourceCreationData) method uses the Source, LogName, and MachineName properties to create registry values on the target computer for the new source and its associated event log. A new source name cannot match an existing source name or an existing event log name on the target computer.

After the registry values for the source are created, your application can use the source to write entries to the configured event log.

Each source can only write to one event log at a time; however, your application can use multiple sources to write to multiple event logs. For example, your application might require multiple sources configured for different event logs or different resource files.

The following code example sets the configuration properties for an event source from command-line arguments. The input arguments specify the event source name, event log name, computer name, and event message resource file. This example is part of a larger example provided for the EventSourceCreationData class.

EventSourceCreationData mySourceData = new EventSourceCreationData("", "");
bool registerSource = true;

// Process input parameters.
if (args.Length > 0)
    // Require at least the source name.

    mySourceData.Source = args[0];

    if (args.Length > 1)
        mySourceData.LogName = args[1];

    if (args.Length > 2)
        mySourceData.MachineName = args[2];
    if ((args.Length > 3) && (args[3].Length > 0))
        mySourceData.MessageResourceFile = args[3];
    // Display a syntax help message.
    Console.WriteLine(" source [event log] [machine name] [resource file]");

    registerSource = false;

// Set defaults for parameters missing input.
if (mySourceData.MachineName.Length == 0)
    // Default to the local computer.
    mySourceData.MachineName = ".";
if (mySourceData.LogName.Length == 0)
    // Default to the Application log.
    mySourceData.LogName = "Application";

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0