Reputation: 65
In my project (ASP.NET C# class library project) , we are using NLog.dll (v 4.0.0.0) to log exceptions in Event Viewer in the below manner:-
private readonly NLog.Logger _logger;
_logger = LogManager.GetCurrentClassLogger();
_logger.Error(someText, someArgs);
Please find the NLog configurations used as below :
target xsi:type="EventLog"
name="eventlog"
layout="${message}"
machineName="."
source="NLogLogger"
log="Application"
It works fine and logs messages in the Application Log inside "Windows Logs". However, we require the logging to be performed in a separately designated log (custom log, specific for my application under "Application and Services Logs").
We specified the name of the designated log in the config like below:-
target xsi:type="EventLog"
name="eventlog"
layout="${message}"
machineName="."
source="NLogLogger"
log=“MyOwnLog”
But it still logs messages in the same Application log.
Please let me know how I can get it logged in the designated log using NLog.
Upvotes: 1
Views: 927
Reputation: 41
I had the same issue. It's probably the source parameter. In PowerShell you have to create the Eventlog like this:
new-eventlog -Source NLogLogger -LogName MyOwnLog
After this you can use your config.
Upvotes: 2