Friday 15 July 2011

EventLog WriteEntry not does not write into EventViewer in C# -



EventLog WriteEntry not does not write into EventViewer in C# -

i have created c# application creates custom log name in event viewer, , writing entries event viewer.

my application working fine on windows-7 os machine when copied binaries window-2012 server standard(sp1) machine not working.

i ran application runas administrator , seeing custom log name not logging messages.

i have given total permission in registry eventlog entry no luck. suggest me how prepare issue. or debugging technique prepare issue.

i have debugged code there no exceptions, code running smoothly. code simple below:

eventlog.createeventsource("myapp", "testingapplication") eventlog.writeentry("myapp", "testing 123")

today have tested same eventsource , eventlogname, below eventlog.createeventsource("myapp", "myapp") worked fine in window-2012 server standard(sp1), there issue in win-2012(sp1) or missing anything.

even while running administrator, in windows server 2008 r2 defaults not having elevated privileges. need elevated privilege create source. 1 time source created, should allow write it.

there few ways solve this, if you're building actual application, can modify application manifest require elevated privileges , admin rights:

<?xml version="1.0" encoding="utf-8" ?> <asmv1:assembly manifestversion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <assemblyidentity version="1.0.0.0" name="myapplication" /> <trustinfo xmlns="urn:schemas-microsoft-com:asm.v2"> <security> <requestedprivileges xmlns="urn:schemas-microsoft-com:asm.v3"> <requestedexecutionlevel level="requireadministrator" uiaccess="false" /> </requestedprivileges> </security> </trustinfo> </asmv1:assembly>

or, 1 time again if you're building normal application, can split code create event source separate process. can check see if event source exists, if does, utilize it, if not, can run new process creates event source.

in process start info you'll need 'runas' verb.

if you're running windows service, you're bit more restricted, services not have capability of "elevating" privileges through manifest straight far i'm aware.

however, service installer can elevate fine, , should running under needed admin rights, can create event source within service installer; , consume within service itself.

c#

No comments:

Post a Comment