布局渲染器可以用于文件名吗?
Can layout render(s) be used for FileName(s)?
布局渲染(确切地说是进程名称)可以用于文件名吗?
注意,
internalLogFile
(和 INTERNAL.log 值)
和
fileName="${processname}.NLog.${shortdate}.PeanutButter.log"
以下值。
<?xml version="1.0" encoding="utf-8" ?>
<!-- XSD manual extracted from package NLog.Schema: https://www.nuget.org/packages/NLog.Schema-->
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xsi:schemaLocation="NLog NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogFile="${processname}.NLog.INTERNAL.log"
internalLogLevel="Trace" >
<!-- the targets to write to -->
<targets>
<!-- write logs to file -->
<target xsi:type="File" name="target1" fileName="${processname}.NLog.${shortdate}.PeanutButter.log"
layout="${date}|${level:uppercase=true}|${logger}|${environment-user:userName=true:domain=true}|****|${message} ${exception:format=toString,Data}|${all-event-properties}" />
<target xsi:type="Console" name="target2"
layout="${date}|${level:uppercase=true}|${logger}|${message} ${exception:format=toString,Data}|${all-event-properties}" />
</targets>
<!-- rules to map from logger name to target -->
<rules>
<logger name="*" minlevel="Trace" writeTo="target1,target2" />
</rules>
</nlog>
根据以上内容,我正在创建一个文件:
${processname}.NLog.INTERNAL.log
(字面意思就是文件名)
并且根本没有文件命名为:
*PeanutButter.log
其中 * 是通配符搜索。
下面是导入的包。
<ItemGroup>
<PackageReference Include="NLog" Version="4.6.8" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.6.1" />
</ItemGroup>
Can layout render(s) (processname to be exact) be used for FileName(s)?
文件目标
是的,文件目标完全支持它。
请参阅 Filetarget docs 中的这个简单示例:
Per-level log files
Single File target can be used to write to multiple files at once.
The following configuration will cause log entries for each log level
to be written to a separate file, so you will get:
- Trace.log
- Debug.log
- Info.log
- Warn.log
- Error.log
- Fatal.log
<target name="file" xsi:type="File"
layout="${longdate} ${logger} ${message}${exception:format=ToString}"
fileName="${basedir}/${level}.log" />
内部记录器
${processname}.NLog.INTERNAL.log
(literally, that is the filename)
不支持内部记录器文件名!
internalLogFile
Note: only a few layouts are supported, as the internal log needs to be as stable as possible.
- NLog 4.6+: Supported renderers (without options):
${currentdir}
, ${basedir}
, ${tempdir}
- NLog 4.6+: Environment Variables are also supported: e.g.
%appdata%
如果内部记录器由于(复杂的)布局渲染器而失败,那么应该在哪里记录呢? ;)
布局渲染(确切地说是进程名称)可以用于文件名吗?
注意,
internalLogFile
(和 INTERNAL.log 值)
和
fileName="${processname}.NLog.${shortdate}.PeanutButter.log"
以下值。
<?xml version="1.0" encoding="utf-8" ?>
<!-- XSD manual extracted from package NLog.Schema: https://www.nuget.org/packages/NLog.Schema-->
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xsi:schemaLocation="NLog NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogFile="${processname}.NLog.INTERNAL.log"
internalLogLevel="Trace" >
<!-- the targets to write to -->
<targets>
<!-- write logs to file -->
<target xsi:type="File" name="target1" fileName="${processname}.NLog.${shortdate}.PeanutButter.log"
layout="${date}|${level:uppercase=true}|${logger}|${environment-user:userName=true:domain=true}|****|${message} ${exception:format=toString,Data}|${all-event-properties}" />
<target xsi:type="Console" name="target2"
layout="${date}|${level:uppercase=true}|${logger}|${message} ${exception:format=toString,Data}|${all-event-properties}" />
</targets>
<!-- rules to map from logger name to target -->
<rules>
<logger name="*" minlevel="Trace" writeTo="target1,target2" />
</rules>
</nlog>
根据以上内容,我正在创建一个文件:
${processname}.NLog.INTERNAL.log
(字面意思就是文件名)
并且根本没有文件命名为:
*PeanutButter.log
其中 * 是通配符搜索。
下面是导入的包。
<ItemGroup>
<PackageReference Include="NLog" Version="4.6.8" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.6.1" />
</ItemGroup>
Can layout render(s) (processname to be exact) be used for FileName(s)?
文件目标
是的,文件目标完全支持它。
请参阅 Filetarget docs 中的这个简单示例:
Per-level log files
Single File target can be used to write to multiple files at once. The following configuration will cause log entries for each log level to be written to a separate file, so you will get:
- Trace.log
- Debug.log
- Info.log
- Warn.log
- Error.log
- Fatal.log
<target name="file" xsi:type="File" layout="${longdate} ${logger} ${message}${exception:format=ToString}" fileName="${basedir}/${level}.log" />
内部记录器
${processname}.NLog.INTERNAL.log
(literally, that is the filename)
不支持内部记录器文件名!
internalLogFile
Note: only a few layouts are supported, as the internal log needs to be as stable as possible.
- NLog 4.6+: Supported renderers (without options):
${currentdir}
,${basedir}
,${tempdir}
- NLog 4.6+: Environment Variables are also supported: e.g.
%appdata%
如果内部记录器由于(复杂的)布局渲染器而失败,那么应该在哪里记录呢? ;)