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
Types of Event Logs They are Information, Warning, Error, Success Audit (Security Log) and Failure Audit (Security Log).
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With