自定义事件查看器 (EventLog) 源列中的文本
是否可以将我想要的源写入事件查看器中的源列?
(而不是“.NET 运行时”?)
如果是这样,怎么办?
Is it possible to write to the Source column in the Event Viewer my wanted source ?
(instead of ".NET Runtime" ?)
And if so, how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在开始菜单中搜索“运行”,打开它,在文本字段中写下“regedit”,然后按“确定”。
现在,我进入“eventlog”文件夹,右键单击“Application”文件夹,选择“New =>”键,然后将其命名为我的项目名称(实际上将显示在事件查看器的“源”列中)。
然后只需在代码中写入:
logName.Source = "MySource";
现在它只能在本地主机中工作。如果您也希望它在服务器中运行 - 只需在服务器中再次打开“运行”,就像第一次一样,但现在它不会直接打开我们需要的内容,因此您必须跟踪与它相同的文件夹包含“Application”文件夹(您会发现它与本地计算机中的位置完全相同),并以相同的方式添加您的源。
祝你好运 !
I searched in start menu for "run", opened it, in the text field I wrote "regedit" and pressed "OK".
Now,I got into "eventlog" folder, right clicked on the "Application" folder, chose New => Key, then named it like my project name (what will actually be shown in Source column in the Event Viewer).
Then simply write in the code :
logName.Source = "MySource";
Now it will work in the localhost only. If you want it to wark in the server too - just open "run" again in the server the same as you did in the first time, but now it will not open directly what we need, so you have to track the same folders that contain the "Application" folder (you will find it exsactly at the same location like in the local computer), and add your sourse in the same way.
Good Luck !
您可以以编程方式配置 EventLogTraceListener 跟踪侦听器:
或使用app/web.config:
然后当您跟踪某些内容时,它将使用配置的跟踪侦听器:
请记住,您需要特殊权限才能创建自定义跟踪侦听器。如果事件日志中不存在自定义源,则前面的代码将尝试创建它,如果没有足够的权限,则会失败。因此,一种可能性是在部署应用程序时以管理员身份创建跟踪侦听器,尤其是当该应用程序在某些低权限帐户(例如 ASP.NET 应用程序)下运行时。
You could configure an EventLogTraceListener trace listener programatically:
or using the app/web.config:
and then when you trace something it will use the configured trace listeners:
Bear in mind that you need special permissions in order to create custom trace listeners. If the custom source doesn't exist in the EventLog the previous code will try to create it and fail if it doesn't have sufficient permissions. So one possibility is to create the trace listener as administrator when deploying the application especially if this application runs under some low privileges account such as an ASP.NET application.