EventSourceCreationData.Source プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
イベント ソースとしてイベント ログに登録する名前を取得または設定します。
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) メソッドは、Source、LogName、およびMachineNameプロパティを使用して、新しいソースとそれに関連付けられたイベント ログのターゲット コンピューターにレジストリ値を作成します。 新しいソース名は、ターゲット コンピューター上の既存のソース名または既存のイベント ログ名と一致できません。
ソースのレジストリ値が作成されると、アプリケーションはソースを使用して、構成されたイベント ログにエントリを書き込むことができます。
各ソースは、一度に 1 つのイベント ログにのみ書き込むことができます。ただし、アプリケーションは複数のソースを使用して複数のイベント ログに書き込むことができます。 たとえば、アプリケーションで、異なるイベント ログまたは異なるリソース ファイル用に構成された複数のソースが必要な場合があります。