EventSourceCreationData.Source 屬性

定義

取得或設定名稱,以註冊事件日誌作為事件來源。

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

屬性值

名稱是用來註冊事件日誌作為條目來源。 預設為空字串(“”)。

範例

以下程式碼範例將設定事件來源的命令列參數的設定屬性。 輸入參數指定事件來源名稱、事件日誌名稱、電腦名稱及事件訊息資源檔案。 此範例是本類別更大 EventSourceCreationData 範例的一部分。

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) 方法利用 SourceLogNameMachineName 屬性,在目標電腦上建立新來源及其相關事件日誌的登錄值。 新的來源名稱無法比對目標計算機上的現有來源名稱或現有的事件記錄檔名稱。

在建立原始碼的登錄檔值後,應用程式可以使用原始碼寫入已設定的事件日誌。

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

適用於

另請參閱