Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Organizing eventlogs into folders

I want to create multiple services and I want them to log each in a log entry under the same directory/folder that I specify so when I open Windows Event Viewer I can see them all placed in one folder. For example service1 would log into service1_log, service2 would log into service2_log and both service1_log and service2_log would reside in one folder named Myservices. I haven't found anything in Windows Event Log API or any other API that would fit into this problem..I can see in windows event viewer there are folders but I can only create logs into the root of the logs hierarchy there.

Thanks in advance Tomas

like image 391
Tomas Avatar asked Jun 17 '11 13:06

Tomas


People also ask

What are the five types of event logs?

Types of Event Logs They are Information, Warning, Error, Success Audit (Security Log) and Failure Audit (Security Log).

Where are Windows event logs stored?

By default, Event Viewer log files use the . evt extension and are located in the %SystemRoot%\System32\winevt\Logs folder. Log file name and location information is stored in the registry.

Can you modify Windows event logs?

In Windows, you can adjust Event Viewer settings by right-clicking the log and clicking Properties. You can adjust the following Event Log settings: Maximum log size. Overwrite events as needed.


2 Answers

Windows Event Log does not log into directories. However, the event log is split into several logs (Application, System, Security etc.) that are presented as folders in Event Viewer. You can create your own log that will appear as a separate folder in Applications and Services Logs (assuming Windows Vista or later) by calling EventLog.CreateEventSource.

However, I will not recommend that you create your own log. Instead you can let your services log to the Application log. By letting each service use a separate event source you can easily filter the Application log to only only display the interesting log messages. Again assuming Windows Vista or later you can create a custom view below the Custom Views node and filter it by source. This folder will then only show log messages from your services.


Fast forward five years: Now, it is quite easy to create you own log that can be seen in Application and Services Logs by using the EventSource class which allows you to create events for Event Tracing for Windows (ETW). ETW is highly configurable, has very good performance but can also be a bit difficult to use initially. Message size is limited, installing a new manifest requires administrative rights, while channels like Diagnostics are collecting data you can't view the log etc. But all in all ETW is a good alternative to logging to the Application event log.

like image 129
Martin Liversage Avatar answered Oct 05 '22 02:10

Martin Liversage


Long story short, it is not easily accomplished using the .NET 4 framework. It looks like .NET 4.5 offers better support for this, but is is not terribly simple. You can put them into folders per application, but putting those folders in a common folder would be a lot more complex.

See the following answser on another thread: https://stackoverflow.com/a/10528920/848419

like image 39
VoteCoffee Avatar answered Oct 05 '22 01:10

VoteCoffee