Да, указываете не minlevel, а levels в logger
а в target конфигурируете layout
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
<logger name="*" levels="Debug" writeTo="f" />
NLog wiki
LayoutsLayout renderers
Ну еще куски NLog.xsd (из nuget'а можно поставить)
<xs:attribute name="levels" type="NLogLevelList">
<xs:annotation>
<xs:documentation>Comma separated list of levels that this rule matches.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:simpleType name="NLogLevel">
<xs:restriction base="xs:string">
<xs:enumeration value="Off" />
<xs:enumeration value="Trace" />
<xs:enumeration value="Debug" />
<xs:enumeration value="Info" />
<xs:enumeration value="Warn" />
<xs:enumeration value="Error" />
<xs:enumeration value="Fatal" />
</xs:restriction>
</xs:simpleType>
Минимальный пример:
Пакеты в проекте:
<packages>
<package id="NLog" version="4.2.0" targetFramework="net452" />
<package id="NLog.Config" version="4.2.0" targetFramework="net452" />
<package id="NLog.Schema" version="4.0.0" targetFramework="net452" />
</packages>
Конфиг nlog:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log" >
<targets>
<target xsi:type="File" name="debug" fileName="${basedir}/logs/${shortdate}.log" layout="DEBUG ${longdate} ${uppercase:${level}} ${message}" />
<target xsi:type="File" name="info" fileName="${basedir}/logs/${shortdate}.log" layout="INFO ${longdate} ${uppercase:${level}} ${message}" />
<target xsi:type="File" name="errors" fileName="${basedir}/logs/${shortdate}.log" layout="ERROR ${longdate} ${uppercase:${level}} ${message}" />
</targets>
<rules>
<logger name="*" levels="Debug" writeTo="debug" />
<logger name="*" levels="Info" writeTo="info" />
<logger name="*" minlevel="Warn" writeTo="errors" />
</rules>
</nlog>
Текст программы:
using System;
using NLog;
namespace ConsoleSandboxApplication
{
class Program
{
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
static void Main(string[] args)
{
try {
_logger.Debug("test debug message");
_logger.Info("some information about program in runtime");
throw new NotImplementedException("not implemented exception");
}
catch (Exception ex) {
_logger.Error(ex);
}
}
}
}
Вывод в лог будет в этом случае таким:
DEBUG 2015-11-10 09:49:55.7685 DEBUG test debug message
INFO 2015-11-10 09:49:55.8275 INFO some information about program in runtime
ERROR 2015-11-10 09:49:56.7916 ERROR System.NotImplementedException: not implemented exception
at ConsoleSandboxApplication.Program.Main(String[] args) in S:\projects\other\ConsoleSandboxApplication\ConsoleSandboxApplication\Program.cs:line 20