Question

How do you change the source name when writing to the event viewer in C# language?

Currently have this

string cs = "Application";

            if (!EventLog.SourceExists(cs))
            EventLog.CreateEventSource(cs, "ReceiveDaily");
            EventLog.WriteEntry(cs, message.Message, EventLogEntryType.Error);

If I change CS to anything else, I see a Security-Kerberos (0x7) popping up at my event viewer It writes the error in the errorlog when I put "Application" though. But then the source is "Application", which isn't a very good description from where it comes ...

Thanks in advance.

Was it helpful?

Solution

As @Phil mentions, I don't think that you can dynamically create event sources unless you are running in admin mode.

However, if you know the set of sources that your application needs, then you can pre-install them using a System.Diagnostics.EventLogInstaller and InstallUtil.exe. These sources will then be available to use by your application.

This has a good example of setting up the installer.

OTHER TIPS

You will need to run your app in admin mode.

You can do this from explorer by right clicking on your app and selecting 'Run as administrator'.

Alternatively you could add a manifest to your app so that it automatically requests admin privileges when run.

The final (and worst from a security point of view) option is to disable UAC via the control panel.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top