Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'd like to use Windows Eventlogging in my C# application "MyApp" on Windows 7. "My App" consists of different projects / components. I want each Component to log under a different folder in Eventviewer under the "My App" folder.

So my eventviewer looks like this:

EventViewer \ Application & Services Logs \ MyApp \ Component \ ...

I know a similair discussion has been in this thread:

How to create event log under a folder[^]

However the central question has NOT been answered I think. The original question, just like mine is how to manage the structure of eventlog.

For example look at the MicroSoft entry in Application & Services logs, it has a subentry for Windows.

Any help will be much appreciated.
Posted

1 solution

 
Share this answer
 
Comments
netogg 14-Oct-11 12:17pm    
Unfortunately this does not answer my question. Google produces a lot of similair examples. Indeed I know how to create and write to an Eventlog.

But I want to know specifically how to create different (sub, sub, sub)folders under "Application & Service Logs", in Eventviewer like mentioned in the original question. Just like the "Microsoft" entry.

If I misunderstood you maybe you could write a concrete example?

Thanks for your quick reply.
Macro Man 14-Oct-11 13:57pm    
It will help if you show us how you are creating your log (not its entries).
netogg 14-Oct-11 19:49pm    
At the moment I have:

// *** log creation rules ***
// - must have admin right on Windows Vista and up
// - only first eight chars are discriminating and must be unique
// - will automaticalle create new log if not existant
// - needs some time to create and refresh, or reboot app
// - cannot be written until created
// - App name == source and must be unique
// - logs go default under Appplication Log
// - since source name must be unique check it before creation otherwise exceptiom
// - source doe not really have to exist as a code file...???!!! -> no
// - also logname must be unique
// - must use system diagnostics namespace
// - must open a new instance of eventlogger to see it; refresh does not work // sometimes it does work? test
// - deletes work direct
// - log to delete must exist first
// - sourcename still exist after log is deleted; reboot required?
// http://msdn.microsoft.com/en-us/library/2awhba7a.aspx for conditions

// Should create the following eventviewer structure:
// Eventviewer
// Application & Services Logs
// ApplicationName
// Service
// UI
// etc...
if (!System.Diagnostics.EventLog.SourceExists("11ApplicationName") && !System.Diagnostics.EventLog.SourceExists("11ApplicationName"))
{
System.Diagnostics.EventLog.CreateEventSource("11ApplicationName", "folder");
System.Diagnostics.EventLog.CreateEventSource("12ApplicationName", "subfolder");
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900