EventSourceCreationData.LogName Property


Gets or sets the name of the event log to which the source writes entries.

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

public string LogName { get; set; }

Property Value

Type: System.String

The name of the event log. This can be Application, System, or a custom log name. The default value is "Application."

Use the LogName property to identify the event log that your application writes entries to using the new source. The event log can be a new log or an existing log. Applications and services should write to the Application log or a custom log. Device drivers should write to the System log. If you do not explicitly set the LogName property, the event log defaults to the Application log.


The Security log is read-only.

To target an existing log for the new source, set the LogName property to the existing event log name. To create a new event log for the source, you must set the LogName property. Event log names must consist of printable characters, and cannot include the characters '*', '?', or '\'. The first 8 characters of the event log name must be different from the first 8 characters of existing names of event logs on the specified computer.

The operating system stores event logs as files. When you use EventLogInstaller or the CreateEventSource method to create a new event log, the associated file is stored in the %SystemRoot%\System32\Config directory on the specified computer. The file name is set by appending the first 8 characters of the LogName property with the ".evt" file name extension.

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";


for calling any member of EventSourceCreationData with full trust. Associated enumeration: PermissionState.Unrestricted

.NET Framework
Available since 2.0
Return to top