首页 > 解决方案 > 使用 Nlog 将 VS 调试日志记录到 Redis 服务器

问题描述

我正在使用 NLog 将调试信息记录到 Redis 服务器。在服务器上运行良好。以下是 Nlog.Config 文件

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      throwExceptions="false" autoReload="true">
  <extensions>
    <add assembly="App.Host" />
  </extensions>
  <targets>
    <target xsi:type="LoggingContextWrapper" name="logstash">
      <target xsi:type="AsyncWrapper">
        <target xsi:type="Redis" host="hostname" key="logstash" dataType="list" port="6379" password="password">
          <layout xsi:type="JsonLayout">
            <attribute name="application" layout="testapplication"/>
            <attribute name="environment" layout="develop"/>
            <attribute name="time" layout="${longdate}"/>
            <attribute name="level" layout="${level:upperCase=true}"/>
            <attribute name="appdomain" layout="${appdomain}"/>
            <attribute name="asp-request" layout="${asp-request}"/>
            <attribute name="logger" layout="${logger}"/>
            <attribute name="machinename" layout="${machinename}"/>
            <attribute name="basedir" layout="${basedir}"/>
            <attribute name="message" layout="${message}"/>
            <attribute name="type" layout="cornerstone"/>
            <attribute name="@fields" layout="!fields"/>
            <attribute name="@tags" layout="!tags"/>
            <attribute name="@requestIds" layout="!requestIds"/>
          </layout>
        </target>
      </target>
    </target>
  </targets>
  <rules>

    <logger name="Api" minlevel="Info" writeTo="logstash" final="true" />

  </rules>
</nlog>

日志记录代码是这样的

Logger apiLogger = LogManager.GetLogger("Api");
apiLogger.Log(infoString);

现在我想在服务器上也有我的 VS 调试日志,所以我在 NLog.Config 文件中进行了以下更改

 <logger name="Api" minlevel="Debug" writeTo="logstash" final="true" />

还将 C# 方法更改为

apiLogger.Debug(infoString);

但我无法在 Redis 服务器上看到调试日志详细信息。还有什么我需要做的吗?

标签: c#redisnlog

解决方案


推荐阅读