EventSourceCreationData.LogName 属性
定义
获取或设置事件日志的名称,事件源要向该日志写入项。Gets or sets the name of the event log to which the source writes entries.
public:
property System::String ^ LogName { System::String ^ get(); void set(System::String ^ value); };
public string LogName { get; set; }
member this.LogName : string with get, set
Public Property LogName As String
属性值
事件日志的名称。The name of the event log. 这可以是 Application、System 或一个自定义的日志名称。This can be Application, System, or a custom log name. 默认值为“Application”。The default value is "Application."
示例
下面的代码示例通过命令行参数设置事件源的配置属性。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. 此示例是为类提供的更大示例的一部分 EventSourceCreationData 。This 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
注解
使用 LogName 属性来标识应用程序将条目写入到使用新源的事件日志。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. 如果未显式设置 LogName 属性,则事件日志会默认为应用程序日志。If you do not explicitly set the LogName property, the event log defaults to the Application log.
备注
安全日志为只读。The Security log is read-only.
若要以新源的现有日志为目标,请将 LogName 属性设置为现有的事件日志名称。To target an existing log for the new source, set the LogName property to the existing event log name. 若要为源创建新的事件日志,则必须设置 LogName 属性。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 '\'. 事件日志名称的前8个字符必须不同于指定计算机上的现有事件日志名称的前8个字符。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. 当使用 EventLogInstaller 或 CreateEventSource 方法创建新的事件日志时,关联的文件将存储在指定计算机上的%SystemRoot%\System32\Config 目录中。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. 文件名的设置方法是将属性的前8个字符追加到 LogName 文件扩展名 ".evt"。The file name is set by appending the first 8 characters of the LogName property with the ".evt" file name extension.