How to Create Windows Event Logs for WPF App
Today, I shall be demonstrating registration of your targeted software's event log entry into windows application event logs using WPF application.
Prerequisites:
Following are some prerequisites before you proceed any further in this tutorial:- Knowledge of WPF Application Development.
- Knowledge of C# Programming.
Download Now!
Let's begin now.1) Create new C#.NET WPF application and name it "WPFWindowsEventLog".
... private void LogEventMessage(string msg) { ... // Create an EventLog instance and assign its source. EventLog myLog = new EventLog(); myLog.Source = this.logSrcName; // Write an informational entry to the event log. myLog.WriteEntry(msg, EventLogEntryType.Information, this.winEventID); ... } ...
In the above lines of code, know that 'logsrcName' and 'winEventID' variables will uniquely identify your log entry inside windows application log event You can then utilize the 'LogEventMessage(...)' method whenever you want your software to output important internal messages related to errors or plain information.
4) Whatever log source name you choose, you need to register that name into windows system registry, by executing below registry line i.e.
...
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application\MyAppLogSrc]
...
5) Now, execute the project and start registering the windows log event, you will be able to see the following i.e.
Now, open 'Computer Management' by opening windows 'Run' command and type 'CompMgmtLauncher' command. Then under Computer Management (Local) -> System Tools -> Event Viewer -> Application and you will see following i.e.
Post a Comment