繁体   English   中英

自定义事件未显示在事件日志中

[英]Custom events not showing up in event log

我正在尝试写入应用程序事件日志。 以下代码在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);
        }
    }
}

根据Microsoft网站,我们有以下信息:

注意:如果源已映射到日志并将其重新映射到新日志,则必须重新启动计算机才能使更改生效。

每次创建新的自定义事件密钥时都必须重新启动计算机。 (或者只是重新启动EventViewer服务):)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM