4

アプリケーション イベント ログに書き込もうとしています。次のコードは、Windows 8 で (管理者権限で実行した場合) エラーなしで実行されますが、Windows イベント ビューアーでアプリケーション ログを確認すると、イベントが表示されません。誰かが私が間違っていることを理解するのを手伝ってくれますか? app.config に何か追加する必要がありますか?

using System.Diagnostics;
namespace tracetest2
{
    class Program
    {
        static void Main(string[] args)
        {
            if (!EventLog.SourceExists("TestSource"))
            {
                EventLog.CreateEventSource("TestSource", "Application");
            }
            EventLog appLog = new EventLog("Application", ".", "TestSource");
            appLog.EnableRaisingEvents = true;
            appLog.EndInit();
            Debug.WriteLine(appLog.Entries.Count);
            appLog.WriteEntry("An entry to the Application event log.");
            Debug.WriteLine(appLog.Entries.Count);
        }
    }
}
4

1 に答える 1