EventSourceCreationData.LogName 屬性

定義

取得或設定要讓來源寫入項目的事件記錄檔名稱。

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

屬性值

事件記錄檔的名稱。 這可以是應用程式、系統或自訂的記錄檔名稱。 預設值是「應用程式」。

範例

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

備註

LogName使用屬性來識別應用程式使用新來源將專案寫入的事件記錄檔。 事件記錄檔可以是新的記錄檔或現有的記錄檔。 應用程式和服務應該寫入應用程式記錄檔或自定義記錄檔。 設備驅動器應該寫入系統記錄檔。 如果您未明確設定 LogName 屬性,事件記錄檔會預設為應用程式記錄檔。

注意

安全性記錄檔是唯讀的。

若要以新來源的現有記錄為目標,請將 LogName 屬性設定為現有的事件記錄檔名稱。 若要為來源建立新的事件記錄檔,您必須設定 LogName 屬性。 事件記錄檔名稱必須包含可列印的字元,而且不能包含字元 『*』、'?' 或 '\'。 事件記錄檔名稱的前8個字元必須與指定電腦上現有事件記錄檔名稱的前8個字元不同。

作業系統會將事件記錄檔儲存為檔案。 當您使用 EventLogInstallerCreateEventSource 方法來建立新的事件記錄檔時,相關聯的檔案會儲存在指定計算機上的 %SystemRoot%\System32\Config 目錄中。 檔名是藉由附加屬性的前 LogName 8 個字元加上 「.evt」 擴展名來設定。

適用於

另請參閱