如何存储事件日志文件夹中 [英] How to store event log in Folder
问题描述
在一个ASP NET项目(C#)我使用System.Diagnostics命名空间来记录错误,警告和信息。
使用Windows 7我看到,我已经为项目设置日志是在应用程序和服务日志。
我怎样才能在code设置为创建一个文件夹,并把它在应用程序和服务日志[某个文件夹] \\应用程序和服务日志,为例子?
On an ASP NET project (C#) I'm using the System.Diagnostics namespace to log errors, warning and information. Using Windows 7 I see that the log I've set for the project is under "Applications and Services Logs". How can I set in code to create a folder and put it under "Applications and Services Logs[SOME FOLDER]\Applications and Services Logs", for examples?
推荐答案
创建当你的事件来源
,指定日志名称
。它将成为在事件查看器的文件夹。
When creating your Event Source
, specify a Log Name
. It will become the "folder" in the Event Viewer.
EventLog.CreateEventSource("Source", "Log name");
EventLog.WriteMessage("Source", "Your message");
请注意,创建一个事件源可能需要在机器上的其他权利。在一个ASP.Net背景下,我建议创建创建事件源Windows或控制台应用程序。一旦运行它作为一个管理员。
Be aware that creating an event source may require additional rights on the machine. In an ASP.Net context, I suggest to create a windows or console application that create the Event Source. Run it once as an administrator.
这篇关于如何存储事件日志文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!