event-log

.NET : How to set user information in an EventLog Entry?

别等时光非礼了梦想. 提交于 2019-11-28 13:57:18
The System.Diagnostics.EventLog class provides a way to interact with a windows event log. I use it all the time for simple logging... System.Diagnostics.EventLog.WriteEntry("MyEventSource", "My Special Message") Is there a way to set the user information in the resulting event log entry using .NET? Toughie ... I looked for a way to fill the user field with a .NET method. Unfortunately there is none, and you must import the plain old Win32 API [ReportEvent function]( http://msdn.microsoft.com/en-us/library/aa363679(VS.85).aspx) with a DLLImportAttribute You must also redeclare the function

GetNumberOfEventLogRecords returns incorrect number of event logs

偶尔善良 提交于 2019-11-28 13:55:47
问题 I have this C++ code to read the event log records DWORD GetLogRecords(LPCWSTR wsLogFile) { HANDLE hEvt = OpenEventLog(NULL, wsLogFile); if (hEvt==NULL) return 0; DWORD dwTotalRecords; BOOL res = GetNumberOfEventLogRecords(hEvt, &dwTotalRecords); CloseEventLog(hEvt); return (res != 0) ? dwTotalRecords : 0; } Result atlTraceGeneral - C:\Windows\system32\winevt\logs\ACEEventLog.evtx - 23499 Total Records atlTraceGeneral - C:\Windows\system32\winevt\logs\Application.evtx - 23499 Total Records

Improve performance of reading event log [duplicate]

夙愿已清 提交于 2019-11-28 12:00:54
问题 This question already has answers here : What is the Fastest way to read event log on remote machine? (8 answers) Closed 2 years ago . I am queries event log of different domain controllers, I have to keep querying that after some time interval. Below is the code I am using to query it. public static void FindAllLog(string machineName) { //EventLog log = new EventLog("", ""); //log. EventLog[] remoteEventLogs; // Gets logs on the local computer, gives remote computer name to get the logs on

How to create a .NET event log source using WiX

风格不统一 提交于 2019-11-28 09:54:24
This is an intentional semi-duplicate of How do you create an event log source using WiX and WIX: Create EventSource using .NET message file . My first question is, does it really have to be so complicated? Isn't there some way to simply specify to WiX, "my program is a .Net program, and it needs to write to the event log - please do the necessary setup"? OK, assuming that isn't possible, I'd like to receive any recommendations for the necessary WiX statements to make it work, irrespective of which version of .Net Framework is installed, and irrespective of whether it is a 32 or 64-bit system.

What is the best way to write event log entries?

假如想象 提交于 2019-11-28 05:31:28
I recently had a problem during the deployment of a windows service. Four computers did not cause any problems, but on the fifth any attempt to start the service failed due to an exception. The exception stack trace is written to the event log, so I though it should be easy to identify the cause: protected override void OnStart(string[] args) { EventLog.WriteEntry("Starting service", EventLogEntryType.Information); try { //... base.OnStart(args); } catch (Exception ex) { EventLog.WriteEntry("Service can not start. Stack trace:" + ex.StackTrace, EventLogEntryType.Error); Stop(); return; }

How do I create a hierarchy of lognames in the Windows event system?

孤街醉人 提交于 2019-11-28 05:01:23
I am logging messages using Enterprise Library. I want some of these (typically errors and warnings) to be passed to the Windows event-system). I today route these via entlib.config. This solution works and so far, so good. But, I have more needs than what this solution provides me. I have multiple installations that should log to different logs, but I want their names to be logical and intuitive in the event-viewer. But, the Windows event-system cannot have two categories where the first 8 characters in the name are the same. The category-name can be longer, but only the first 8 letters is

The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security [duplicate]

℡╲_俬逩灬. 提交于 2019-11-28 04:17:14
This question already has an answer here: The source was not found, but some or all event logs could not be searched 8 answers I am getting error: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security When I run below code to capture errors on Win 2K12 R2 server IIS 8.5 EventLog elog = new EventLog(); EventLog.CreateEventSource("MyApp", "Application"); EventLog.WriteEntry(Source, swError.ToString(), EventLogEntryType.Error); I've given full access to HKLM\SYSTEM\CurrentControlSet\services\eventlog but it is not working still. What shall I do to

Subscription to Windows Event Log?

筅森魡賤 提交于 2019-11-28 01:20:39
问题 I'm working on a project that needs to check the Windows Event Log frequently for certain events. I'm wondering - is there a way to create a subscription to the Windows Event Log for certain events? So, when the event happens (e.g. event id = 00001), I can get a notification in the code? If this cannot be done, then I will have to keep searching the event log, which is not efficient. 回答1: As you're using C#, I think you should use Windows API to subscribe to certain Windows events. You can do

EventLog write permissions

你。 提交于 2019-11-27 21:52:44
My question is related to write permissions to the Windows Event Log. I have looked around several posts concering this, and have found some ways to solve my problem, but none of these are acceptable for my current scenario. I use C# in .NET 4.0. I use the EventLog class: EventLog class In short, I need to see if there is a way to impersonate or authenticate with an authenticated user and password to reach the right I need to write to the Event Log. The server will always be in the Windows Server family, but the version may vary. My application is a Windows Service running with one of the

What is the Fastest way to read event log on remote machine?

自作多情 提交于 2019-11-27 20:15:15
I am working on an application which reads eventlogs(Application) from remote machines. I am making use of EventLog class in .net and then iterating on the Log entries but this is very slow. In some cases, some machines have 40000+ log entries and it takes hours to iterate through the entries. what is the best way to accomplish this task? Are there any other classes in .net which are faster or in any other technology? ChrisW Man, I feel your pain. We had the exact same issue in our app. Your solution has a branch depending on what server version you're running on and what server version your