【发布时间】:2014-08-29 07:40:57
【问题描述】:
我知道在 SO 上有很多关于写给事件查看器的主题,但我没有找到我需要的。
我有以下代码在事件查看器中创建一个新的事件日志类别:
string sSource = "MyWebService";
string sLog = "My Application";
string sMsg = "Error Message Goes here";
if (!EventLog.SourceExists(sSource))
{ EventLog.CreateEventSource(sSource, sLog); }
这按预期工作,在事件查看器中,我有以下输出:
所以,写入事件查看器不是问题,但是当我想在日志中创建一些层次结构时,就会出现问题。
所以,假设我编写了一个由各种组件组成的应用程序:
- MVC
- Web API
- Windows Service
然后在事件查看器中,我想创建一个包含所有这些元素的字典,就像 Microft 所做的那样:
这意味着我想要一个如下所示的输出:
- Application (directory)
- MVC (directory)
- Others (logs)
- Web API (directory)
- Demo (logs)
- Windows Service (directory)
- Authentication (logs)
我已尝试执行以下操作:
string sSource = "MyWebService";
string sLog = "My Application";
string sMsg = "Error Message Goes here";
if (!EventLog.SourceExists(sSource))
{ EventLog.CreateEventSource(sSource, sLog); }
if (!EventLog.SourceExists(sLog))
{ EventLog.CreateEventSource(sLog, "Web Service"); }
当然,这没有用。
有人知道如何在事件查看器中创建层次结构吗?
重要的是:我喜欢完全控制我的代码,所以我不想使用任何第三方库。
【问题讨论】:
标签: c# event-log event-viewer