Windows EventLog - populating User field

G

Guest

Hi

I'm using the following code in a global class to add to the Windows
EventLog every time a try{} catch{} block fails...

if(!EventLog.SourceExists("darts"))
EventLog.CreateEventSource("darts", "Darts");

EventLog.WriteEntry("darts", msg, EventLogEntryType.Error);

This works great, but it doesn't populate the User field in the EventLog (it
says N/A). I'd like this to be populated with the value of
HttpContext.Current.User.Identity.Name.

Is it possible to populate this field!?
 
S

Steven Cheng[MSFT]

Hi muso,

Thank you for posting.

As for the .net EventLog Class's WriteEntry method, it calls the win32
"ReportEvent" API internally, also it always set "Null" to the userid
parameter for the ReportEvent API, this is why the written event entry
won't contains username info. Also, generally the userid info is not quite
used for application eventlog, it is mainly used for security log. If you
want to attach username info to the application eventlog (through .NET
api), you can consider append it to other text field like description.
Otherwise, we may need to directly use the WIN32 API to write eventlog
entry...


Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Guest

Hi Steven

Thanks for the reply... I'm thinking I'll find another way round this,
rather than delving into WIN32... the project doesn't warrant the time
necessary!

Cheers for the response!


Dan
 
S

Steven Cheng[MSFT]

Thanks for the response Dan,

Please feel free to let me know if there's anything else we can help.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top