NLog 不写入调试消息

2024-01-01

在我的代码中我有一些信息消息,例如logger.Log("dwewe") and logger.Debug("ddddf").

问题是即使我在 VS 中调试,调试消息也不会被写入。

<?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"
      throwExceptions="true"
      internalLogLevel="Trace"
      internalLogFile="c:\nlog-app.log"
      autoReload="false"
      internalLogToConsole="true">
  <!--
  See http://nlog-project.org/wiki/Configuration_file
  for information on customizing logging rules and outputs.
   -->
  <targets>
    <!-- file targets -->
    <target name="asyncFile" xsi:type="AsyncWrapper">
      <target xsi:type="File" name="f" fileName="${basedir}/Logs/${shortdate}.log"
            layout="${longdate} ${uppercase:${level}} ${message} ${event-context:item=error-source} ${event-context:item=error-class} ${event-context:item=error-method} ${event-context:item=error-message} ${event-context:item=inner-error-message} ${event-context:item=stack-trace}"/>
    </target>

    <!-- database targets -->
    <target name="database" xsi:type="Database" keepConnection="true" useTransactions="true"
             dbProvider="System.Data.SqlClient"
             connectionString="data source=XXXXXX.database.windows.net;initial catalog=NLog;integrated security=false;persist security info=True;User ID=XXXXr;Password=BXXXX3"
              commandText="INSERT INTO Logs(EventDateTime, EventLevel, UserName, MachineName, EventMessage, ErrorSource, ErrorClass, ErrorMethod, ErrorMessage, InnerErrorMessage, StackTrace) VALUES (@EventDateTime, @EventLevel, @UserName, @MachineName, @EventMessage, @ErrorSource, @ErrorClass, @ErrorMethod, @ErrorMessage, @InnerErrorMessage, @StackTrace)">
      <!-- parameters for the command -->
      <parameter name="@EventDateTime" layout="${date:s}" />
      <parameter name="@EventLevel" layout="${level}" />
      <parameter name="@UserName" layout="${windows-identity}" />
      <parameter name="@MachineName" layout="${machinename}" />
      <parameter name="@EventMessage" layout="${message}" />
      <parameter name="@ErrorSource" layout="${event-context:item=error-source}" />
      <parameter name="@ErrorClass" layout="${event-context:item=error-class}" />
      <parameter name="@ErrorMethod" layout="${event-context:item=error-method}" />
      <parameter name="@ErrorMessage" layout="${event-context:item=error-message}" />
      <parameter name="@InnerErrorMessage" layout="${event-context:item=inner-error-message}" />
      <parameter name="@StackTrace" layout="${event-context:item=stack-trace}" />

    </target>

    <target name="console" xsi:type="Console" />

  </targets>
  <rules>
    <!-- add your logging rules here -->
    <logger name="*" minlevel="Info" writeTo="database" />
    <logger name="*" minlevel="Error" writeTo="asyncFile" />
    <logger name="*" minlevel="Trace" writeTo="console" />
  </rules>
</

无法获取Debug的原因是debug是最低级别的日志级别只需在 nlog.config 文件的规则标签中添加以下标签即可。

 <logger name="*" minlevel="Debug" writeTo="console" />
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

NLog 不写入调试消息 的相关文章

随机推荐

  • 实例方法中的静态变量

    假设我有这个程序 class Foo public unsigned int bar static unsigned int counter 0 return counter int main Foo a Foo b 当然这个例子没有任何意
  • python中access数据库表的读写

    我有一个访问数据库 里面是我创建的几张桌子 我想使用 python 读取其中一个表并列出一列中的所有内容 我想将该列表与程序中已创建的另一个列表进行比较 如果该数字与列表中的数字匹配 则在我制作的访问电子表格的同一行新列中输出 是 同样 如
  • MySQL 查询 - 每组最近的条目

    我正在尝试选择表中每组的最新条目 假设我有一个表 blog posts 其中有一列 id 全部唯一 自动递增 post cat 可以是值 category1 或 category2 或 category3 以及一个 publish stat
  • 如何提高 ASP.NET MVC 中从 SQL Server 数据库获取数据的速度 [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我是 ASP NET MVC5 的新手 我有一个模型Shipping and my dbo Shippings sql是这样的 CRE
  • 检查函数是否被调用为装饰器

    在下面的最小示例中decorate被调用两次 第一次使用 decorate 第二个通过正常函数调用decorate bar def decorate func print func name return func decorate def
  • 在 NetworkX 中合并两个加权图

    我使用 python 多重处理来创建多个不同的 NetworkX 图 然后使用下面的函数来组合这些图 然而 虽然这个函数对于小图工作得很好 但对于较大的图 它会使用大量内存 并且会挂在我的系统和内存密集型 AWS 系统上 仅使用系统中总内存
  • 交换两列 - awk、sed、python、perl

    我有一个大文件中的数据 280 列宽 700 万行长 我需要交换前两列 我想我可以使用某种 awk for 循环来执行此操作 打印 2 1 然后打印到文件末尾的范围 但我不知道如何执行范围部分 而且我无法打印 2 1 美元 3 美元 280
  • 在 API 加载之前在 Cordova 中显示 webView

    我正在使用 PhoneGap Cordova 构建适用于 iOS 和 Android 的应用程序 按照标准行为 在 JavaScript 初始化并且 Cordova API 准备就绪之前 不会显示 webView 所以直到我打电话 docu
  • jquery 添加类到这个被点击的元素

    我生成几行 tr 与任务 现在 可以通过单击某个任务将每个任务标记为完成span 我通过 ajax 请求来做到这一点 这是 HTML table tr td 1 td td span class icon complete a to hea
  • foreach 循环和 stdclass 对象

    我在这里看到了类似的问题 但我似乎无法将解决方案应用于我的问题 我有一个名为 results 的变量 它是从 API 获得的 我将更改专有名词以保护我工作的客户 stdClass Object out gt stdClass Object
  • Laravel 混合编译依赖

    我正在尝试使用vuex 模块装饰器 https github com championswimmer vuex module decoratorsLaravel Mix 项目中的库 使用 TypeScript 但我不断收到错误Uncaugh
  • 比较两个 OpenCV 图像/2D Numpy 数组

    我刚开始使用 OpenCV Python 和 Numpy 但已经成为 Java C C 程序员有一段时间了 我正在实现一个 sigma delta 背景检测器 它执行以下操作 设 i1 为第一张图像 设 i2 为第二张图像 for each
  • 将字节数组插入 List 的最简洁方法?

    在某些代码中 我正在创建一个字节列表 并希望在构建它时将一个字节数组插入到该列表中 这样做最干净的方法是什么 请参阅下面的代码 谢谢 public class ListInsert public static byte getData re
  • 安装 MvcScaffolding 包时 NuGet 执行策略错误

    我在项目中使用 Visual Web Developer Express 2010 Windows XP 和 ASP NET MVC4 RC 我安装了 NuGet v2 0 30619 9119 我现在尝试通过 NuGet 包管理器控制台安
  • 在运行脚本的页面上查找 xpath

    我正在尝试使用硒抓取网页 通过检查页面并右键单击建议的 xpath 属于不稳定类型 html body table 2 tbody tr 1 td form table tbody tr 2 所以我尝试了以下解决方案 driver webd
  • 当我们可以创建 String s = "abc" 时,需要什么 String s = new String("abc")

    据我的理解 String s new String abc 将创建两个对象 字符串常量池中的一个 如果 abc 尚未在常量池中 堆内存中的一个 尽管对于实际将创建多少对象以及在何处创建存在多种理解 无论如何 我有以下问题 为什么 Strin
  • 在 NodeJS 中从 Base64 字符串创建图像

    我正在尝试上传从画布中提取并通过 ajax 发布的图像 但在服务器端创建图像文件时遇到问题 我有以下这个答案 https stackoverflow com a 7347358 1358670 https stackoverflow com
  • 在django中使用聚合获取最小值字段名称

    我有一个模型 其中包含如下所示的一些字段 class Choclate models Model name models CharField max length 256 price models IntegerField 所以我想获取具有
  • 将日期时间指定为索引不会给出 DatetimeIndex

    我的 df 有一个名为 天 的字段 我需要从 天 和开始日期创建一个日期时间 可能很麻烦 但它有效 for t in df index df loc t date datetime date startdate datetime timed
  • NLog 不写入调试消息

    在我的代码中我有一些信息消息 例如logger Log dwewe and logger Debug ddddf 问题是即使我在 VS 中调试 调试消息也不会被写入