Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# Write to Event Log

Posted on 2009-05-08
1
Medium Priority
?
1,191 Views
Last Modified: 2012-06-27
The attached is code is used to write an event to the event log, i.e. Application Log. However, it doesn't include the user name that was executed the command. The user name just says N/A. I can include this:

...
sEvent = "Sample Event " + WindowsIdentity.GetCurrent().Name;
...

in the message, but is there a way to have it included in the event log itself?
using System;
using System.Diagnostics;
 
namespace WriteToAnEventLog_csharp
{
	/// Summary description for Class1.
	class Class1
	{
		static void Main(string[] args)
		{
			string sSource;
			string sLog;
			string sEvent;
 
			sSource = "dotNET Sample App";
			sLog = "Application";
			sEvent = "Sample Event";
 
			if (!EventLog.SourceExists(sSource))
				EventLog.CreateEventSource(sSource,sLog);
 
			EventLog.WriteEntry(sSource,sEvent);
			EventLog.WriteEntry(sSource, sEvent,
				EventLogEntryType.Warning, 234);
		}
	}
}

Open in new window

0
Comment
Question by:computerstreber
1 Comment
 
LVL 3

Accepted Solution

by:
nhenny2009 earned 1000 total points
ID: 24341595
I don't think this is possible.  The user that is recorded in the event log is the username associated with the current running thread. I'm don't think there's a way to do this directly through the .NET Framework, and I believe that it is probably by design.  The best workaround would be to write the username you'd like into the message portion of your event entry.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses
Course of the Month5 days, 20 hours left to enroll

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question