首页 > 解决方案 > NLog 没有向控制台输出任何内容

问题描述

我正在关注本教程 https://www.youtube.com/watch?v=jn6X-rx78ZU&list=PLJFgzBCcspK8p7Hxu2OLh-f-x0PBsIGjH&index=15&ab_channel=TheTutorialChef 我正在尝试在最后运行服务器。NLog 应该输出到服务器已经启动的控制台,但是 NLog 没有输出任何东西。我在下面添加了 NLog 配置文件。

<?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"
      xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
      autoReload="true"
      throwExceptions="false"
      internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">

    <!-- optional, add some variables
  https://github.com/nlog/NLog/wiki/Configuration-file#variables
  -->
    <variable name="myvar" value="myvalue"/>

    <!--
  See https://github.com/nlog/nlog/wiki/Configuration-file
  for information on customizing logging rules and outputs.
   -->
    <targets>

        <target name="Console" xsi:type="Console" layout=" ${level} ${date} ${message} ${exception:innerFormat=Message,StackTrace}" />

        <!-- https://github.com/NLog/NLog/wiki/ColoredConsole-target -->
        <target name="CConsole" useDefaultRowHighlightingRules="true" xsi:type="ColoredConsole" layout="${logger} ${level} ${date} ${message} ${exception:innerFormat=Message,StackTrace}" >

        </target>

        <target name="warnfile" xsi:type="File" fileName="${basedir}/Logs/warning.txt"
                maxArchiveFiles="4"
                archiveAboveSize="10240"
                archiveEvery="Day" />

        <target name="infofile" xsi:type="File" fileName="${basedir}/Logs/info.txt"
            maxArchiveFiles="4"
            archiveAboveSize="10240"
            archiveEvery="Day" />

    </targets>

    <rules>
        <!-- add your logging rules here -->

        <logger name="*" minlevel="Info" maxlevel="Warn" writeTo="infofile" />
        <logger name="*" minlevel="Warn" writeTo="warnfile" />
        <logger name="*" minlevel="Trace" writeTo="CConsole" />
    </rules>
</nlog>

但没有任何输出。没有编译错误或警告。我做错了什么?我正在使用 VSCode 2017 和 NLog 4.7.6。我试过直接编辑 .nuget 包中的 cofig 文件。我尝试重新安装 NLog 以获取原始 NLog.config,但是现在当我重新安装 NLog 时,配置文件不再出现在根目录中。

标签: visual-studio-codenlog

解决方案


推荐阅读