Source name when writing to event viewer C#

故事扮演 提交于 2019-12-12 05:07:27

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/9601610/source-name-when-writing-to-event-viewer-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!