Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#3.5
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 14-Oct-11 5:15am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

netogg at 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 at 14-Oct-11 13:57pm
It will help if you show us how you are creating your log (not its entries).
netogg at 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?
// 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)

  Print Answers RSS
0 OriginalGriff 235
1 Sergey Alexandrovich Kryukov 120
2 Richard MacCutchan 100
3 ChauhanAjay 95
4 BotCar 95
0 Sergey Alexandrovich Kryukov 9,056
1 OriginalGriff 8,041
2 CPallini 2,613
3 Richard MacCutchan 2,221
4 Abhinav S 1,928

Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 14 Oct 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100