EventSourceCreationData.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

屬性值

使用事件記錄檔登錄作為項目來源的名稱。 預設為空字串 ("")。

範例

下列程式代碼範例會從命令行自變數設定事件來源的組態屬性。 輸入自變數會指定事件來源名稱、事件記錄檔名稱、計算機名稱和事件訊息資源檔。 這個範例是提供給 類別之較大範例的 EventSourceCreationData 一部分。

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

備註

來源名稱通常是應用程式的名稱,或大型應用程式內的元件名稱。 方法 EventLog.CreateEventSource(EventSourceCreationData)Source使用、 LogNameMachineName 屬性,在目標計算機上為新來源及其相關聯的事件記錄檔建立登錄值。 新的來源名稱無法比對目標計算機上的現有來源名稱或現有的事件記錄檔名稱。

建立來源的登錄值之後,您的應用程式可以使用來源將專案寫入已設定的事件記錄檔。

每個來源一次只能寫入一個事件記錄檔;不過,您的應用程式可以使用多個來源來寫入多個事件記錄檔。 例如,您的應用程式可能需要針對不同的事件記錄檔或不同的資源檔案設定多個來源。

適用於

另請參閱