Identity-layout-renderer未为Dot Net Core CONSOLE应用程序呈现任何内容

问题描述 投票:0回答:1

我有一个DotNetCore控制台应用程序。

像这样:

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
  </PropertyGroup>

我正在运行带有VS 2019的Windows 10。

我无法通过下面的布局渲染器记录任何内容。

https://github.com/NLog/NLog/wiki/Identity-layout-renderer

${identity:authType=Boolean:separator=String:name=Boolean
          :isAuthenticated=Boolean}

我的nlog.config

<?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="MyApp.NLog.INTERNAL.log"
      internalLogLevel="Info" >

  <!-- the targets to write to -->
  <targets>
    <!-- write logs to file -->
    <target xsi:type="File" name="target1" fileName="MyApp.NLog.${shortdate}.log"
            layout="${date}|${level:uppercase=true}|${logger}|***|${identity:authType=true:separator=/:name=true:isAuthenticated=true}|****|${message} ${exception:format=toString,Data}|${all-event-properties}" />

  </targets>



  <!-- rules to map from logger name to target -->
  <rules>
    <logger name="*" minlevel="Trace" writeTo="target1" />
  </rules>
</nlog>

示例日志::(

2020/02/19 12:03:40.617|INFO|MyCompany.MyObject|***||****|HeyYouThere |

*** || **** :(]之间没有任何内容

和nlog内部日志输出(MyApp.NLog.INTERNAL.log)(无错误)

2020-02-19 12:03:38.3612 Info Auto loading assembly file: c:\myfolder1\myfolder2\bin\Debug\netcoreapp3.1\NLog.Extensions.Logging.dll
2020-02-19 12:03:38.3734 Info Loading assembly file: c:\myfolder1\myfolder2\bin\Debug\netcoreapp3.1\NLog.Extensions.Logging.dll
2020-02-19 12:03:38.3847 Info NLog.Extensions.Logging, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 1.6.1.1203. Product version: 1.6.1.
2020-02-19 12:03:38.3847 Info Auto loading assembly file: c:\myfolder1\myfolder2\bin\Debug\netcoreapp3.1\NLog.Extensions.Logging.dll succeeded!
2020-02-19 12:03:38.3847 Info Auto loading assembly file: c:\myfolder1\myfolder2\bin\Debug\netcoreapp3.1\NLog.WindowsIdentity.dll
2020-02-19 12:03:38.3847 Info Loading assembly file: c:\myfolder1\myfolder2\bin\Debug\netcoreapp3.1\NLog.WindowsIdentity.dll
2020-02-19 12:03:38.3938 Info NLog.WindowsIdentity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 4.6.8.10751. Product version: 4.6.8.
2020-02-19 12:03:38.3938 Info Auto loading assembly file: c:\myfolder1\myfolder2\bin\Debug\netcoreapp3.1\NLog.WindowsIdentity.dll succeeded!
2020-02-19 12:03:38.3938 Info Message Template Auto Format enabled
2020-02-19 12:03:38.4652 Info Adding target FileTarget(Name=target1)
2020-02-19 12:03:38.5111 Info Found 39 configuration items
2020-02-19 12:03:38.5614 Info Configuration file change detected! Reloading in 1000ms...
2020-02-19 12:03:38.5614 Info Configuration file change detected! Reloading in 1000ms...
2020-02-19 12:03:39.5688 Info Reloading configuration...
2020-02-19 12:03:39.5688 Info Configuring from an XML element in c:\myfolder1\myfolder2\bin\Debug\netcoreapp3.1\nlog.config...
2020-02-19 12:03:39.5688 Info Message Template Auto Format enabled
2020-02-19 12:03:39.5688 Info Adding target FileTarget(Name=target1)
2020-02-19 12:03:39.5688 Info Closing old configuration.
2020-02-19 12:03:39.5987 Info Found 39 configuration items

Nuget包

  <ItemGroup>
    <PackageReference Include="NLog" Version="4.6.8" />
    <PackageReference Include="NLog.Extensions.Logging" Version="1.6.1" />
    <PackageReference Include="NLog.WindowsIdentity" Version="4.6.8" />
  </ItemGroup>

据我所见,看起来我有nuget包

.nuget\packages\nlog\4.6.8\lib\netstandard2.0\NLog.dll
namespace NLog.LayoutRenderers
{
    [LayoutRenderer("identity")]
    public class IdentityLayoutRenderer : LayoutRenderer

我有一个DotNetCore控制台应用程序。像这样:Exe

c# .net-core nlog
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.