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?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
This is a new feature of .NET 3.5 and available in . Microsoft introduced a new library that is not too user friendly read about it here. It says, most likely out of date, that these classes only work in Windows Vista, however I would hazard a guess that they are accessible in Windows 7 and Server 2008.
I didn't find code there to explain how to create a new hierarchy like you were asking for, however, I believe this in the general direction.
Have you considered using a more generic log mechanism which provides greater flexibility? For example log4net. Then you can switch between log files and event log and also other methods whenever you want without changing a line of code.
When creating your
Event Source
, specify aLog Name
. It will become the "folder" in the Event Viewer.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.
The logs stored in the Applications and Services Log section are the logs of custom event publishers as opposed to simple Windows Event Logs.
From this article Technology Summary for Reading and Managing Event Logs:
Thus, you would need to create a custom Event Publisher. Here are a couple of articles with more information: