<!-- optional, add some variables https://github.com/nlog/NLog/wiki/Configuration-file#variables --> <variablename="myvar"value="myvalue"/>
<!-- See https://github.com/nlog/nlog/wiki/Configuration-file for information on customizing logging rules and outputs. --> <targets>
<!-- add your targets here See https://github.com/nlog/NLog/wiki/Targets for possible targets. See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers. -->
<!-- Write events to a file with the date in the filename. <target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log" layout="${longdate} ${uppercase:${level}} ${message}" /> --> </targets>
<rules> <!-- add your logging rules here -->
<!-- Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f" <logger name="*" minlevel="Debug" writeTo="f" /> --> </rules> </nlog>
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging;
If you are debugging locally make the changes in appsettings.Development.json
The Logging configuration specified in appsettings.json overrides any call to SetMinimumLevel. So either remove "Default": or adjust it correctly to your needs. - github.com/NLog
publicintSetPosition(...) { _logger.LogTrace("This is LogTrace"); _logger.LogDebug("This is LogDebug"); _logger.LogInformation("This is LogInformation"); _logger.LogWarning("This is LogWarning"); _logger.LogError("This is LogError"); _logger.LogCritical("This is LogCritical");
These levels work from minimum (Trace) to maximum (Critical), so if you set your level to Information you will not get logs for Trace and Debug
1 2 3 4 5 6 7
Trace - Very detailed log messages, potentially of a high frequency and volume Debug - Less detailed and/or less frequent debugging messages Information - Informational messages Warning - Warnings which don't appear to the user of the application Error - Error messages Critical - Fatal error messages. After a fatal error, the application usually terminates. None - No logging
You can specify logging to files by class and wildcard, super useful for debugging code flows. For the below I needed only logs for moverules from the name space GameEngine.Services.ComputerMove.MoveRules.*
So for the below I would include _logger.LogTrace("This is LogTrace"); in the code for the MoveRules classes and this data will go into moverules.log
Note that appsettings needs to then be set to Trace.