The correct way to log into EventLog using NLog

How can I avoid window complaints about the lack of descriptions of event identifiers when registering with NLog. When i use:

<target xsi:type="EventLog" name="eventLog" layout="${message}" machineName="." source="MyApp" log="Application" /> 

and

 <rules> <logger name="*" minlevel="Debug" writeTo="eventLog" /> </rules> 

the entry will appear in the log. But Windows complains about the lack of a description for the event identifier "0", which is correct.

Should I do something like here to get a clean log?

+6
source share
2 answers

I know this old post, but the setting should be

 <target xsi:type="EventLog" name="asyncFile" layout="${message}" machineName="." source="MyApp" log="Application" /> 

and

 <rules> <logger name="*" minlevel="Debug" writeTo="asyncFile" /> </rules> 
+3
source

According to the NLog documentation, the eventId tag can be set. https://github.com/nlog/NLog/wiki/EventLog-target

 <targets> <target xsi:type="EventLog" name="String" layout="Layout" machineName="String" source="Layout" category="Layout" eventId="Layout" log="String" /> <!-- note: source is a string in NLog before 4.0 --> </targets> 
0
source

Source: https://habr.com/ru/post/951496/


All Articles