c# - Where should be custom EventLog created? -
i have windows service. i'm struggling eventlog working properly.
in windows service's constructor do:
public myservice() { initializecomponent(); autolog = false; if (!eventlog.sourceexists(servicename)) { eventsourcecreationdata creationdata = new eventsourcecreationdata(servicename, servicename); eventlog.createeventsource(creationdata); } }
after run service, no exceptions, can't see under application , services logs in event viewer! (even after computer reset).
i checked registry , service appears in
hkey_local_machine\system\currentcontrolset\services\myservice
not here:
hkey_local_machine\system\currentcontrolset\services\eventlog\myservice
i install windows service via visual studio's developer command prompt vs2015 opened administrator.
why there? why not in eventlog? why can't see in event viewer?
thanks!
use following code, check source exist before creating it. check naming convention here: https://msdn.microsoft.com/en-us/library/2awhba7a.aspx
string machinename = "myremoteservername"; string source = "mycustomapp"; string logname = "application";//can application, system, or custom log name. if (eventlog.sourceexists(logname, machinename)) return; eventsourcecreationdata eventsourcecreationdata = new eventsourcecreationdata(source, logname); eventsourcecreationdata.machinename = machinename; eventlog.createeventsource(eventsourcecreationdata);
refer: https://msdn.microsoft.com/en-us/library/system.diagnostics.eventsourcecreationdata(v=vs.110).aspx
Comments
Post a Comment