I just started using NLog and logging in general, but I find myself possibly over abusing it. I am logging every single line of code, most of it is Info messages, but in my try catch scenarios or if something is null, I will log an error. What is the best thing to log?
I am using this for a WPF solution that has 2 projects (1 is the UI and the other is a Class library)
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- make sure to set 'Copy To Output Directory' option for this file -->
<!-- go to http://nlog-project.org/wiki/Configuration_file for more information -->
<targets>
<target name="errorLog" xsi:type="File" fileName="${basedir}/error.txt" />
<target name="infoLog" xsi:type="File" fileName="${basedir}/info.txt" />
</targets>
<rules>
<logger name="*" level="Error" writeTo="errorLog" />
<logger name="*" level="Info" writeTo="infoLog" />
</rules>
</nlog>
NLog supports the concept of logging levels.
It is a good idea to log anything that might be useful in tracking down why the program does what it does, using a level less than Error. Set the desired logging level to Error in NLog.config when you deploy your application.
http://nlog-project.org/wiki/Log_Levels
If a user experiences an unexpected problem, you can change the logging level to e.g. Info and get much more information about what is happening.
Having said that, every single line of code is almost certainly overkill. You are cluttering your code with logging if you go to that extreme.
Concentrate on places where things can go wrong in the application.
My personal preference is to: