EventSourceCreationData.Source 属性

定义

获取或设置要在事件日志中注册为事件源的名称。Gets or sets the name to register with the event log as an event source.

public:
 property System::String ^ Source { System::String ^ get(); void set(System::String ^ value); };
public string Source { get; set; }
member this.Source : string with get, set
Public Property Source As String

属性值

String

要在事件日志中注册为项源的名称。The name to register with the event log as a source of entries. 默认值为空字符串("")。The default is an empty string ("").

示例

下面的代码示例通过命令行参数设置事件源的配置属性。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. 此示例是为类提供的更大示例的一部分 EventSourceCreationDataThis example is part of a larger example provided for the EventSourceCreationData class.

EventSourceCreationData ^ mySourceData = gcnew EventSourceCreationData( "","" );
bool registerSource = true;

// Process input parameters.
if ( args->Length > 1 )
{
   
   // Require at least the source name.
   mySourceData->Source = args[ 1 ];
   if ( args->Length > 2 )
   {
      mySourceData->LogName = args[ 2 ];
   }

   if ( args->Length > 3 )
   {
      mySourceData->MachineName = args[ 3 ];
   }

   if ( (args->Length > 4) && (args[ 4 ]->Length > 0) )
   {
      mySourceData->MessageResourceFile = args[ 4 ];
   }
}
else
{
   
   // Display a syntax help message.
   Console::WriteLine( "Input:" );
   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";
}


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];
    }
}
else
{
    // Display a syntax help message.
    Console.WriteLine("Input:");
    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";
}
         Dim mySourceData As EventSourceCreationData = new EventSourceCreationData("", "")
         Dim registerSource As Boolean = 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)
 
             End If
             If args.Length > 2

                 mySourceData.MachineName = args(2)
 
             End If
             If args.Length > 3 AndAlso args(3).Length > 0

                 mySourceData.MessageResourceFile = args(3)
 
             End If

         Else 
             ' Display a syntax help message.
             Console.WriteLine("Input:")
             Console.WriteLine(" source [event log] [machine name] [resource file]")

             registerSource = False
         End If

         ' Set defaults for parameters missing input.
         If mySourceData.MachineName.Length = 0
         
             ' Default to the local computer.
             mySourceData.MachineName = "."
         End If
         If mySourceData.LogName.Length = 0
             ' Default to the Application log.
             mySourceData.LogName = "Application"
         End If

注解

源名称通常是应用程序的名称,或者是大型应用程序中组件的名称。The source name is often the name of the application, or the name of a component within a large application. EventLog.CreateEventSource(EventSourceCreationData)方法使用 SourceLogNameMachineName 属性在目标计算机上为新源及其关联事件日志创建注册表值。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.

适用于

另请参阅