c# - Nlog 记录一个对象

标签 c# logging nlog

假设我想使用 Nlog 记录一个对象 Mycustomer。

我想要这样的东西:

记录器.Trace(我的客户)

现在在配置中如何指定要打印的属性?像这样的东西:

      <target name="output" xsi:type="Debugger" layout="${Name}" />

最佳答案

我明白了

代替 logger.log(customer);

我用它来添加客户的属性:

        NLog.LogEventInfo info = new LogEventInfo(LogLevel.Info,"Name",cus.Name);
        info.Properties.Add("Name",cus.Name);
        log.Log(info);

在配置中我使用它来打印它:

  <target name="output" xsi:type="Debugger" layout="${event-context:item=Name}"  />

关于c# - Nlog 记录一个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5056492/

相关文章:

c# - Visual Studio 2008 文件夹浏览器对话框

c# - 在 Entity Framework 中记录插入和更新命令 sql 查询

azure - NLog 将 UTC 转换为 Azure 中的本地时区?

java - Java 11 中的垃圾收集 JVM args 是否有替代品?

java - Maven/Sonar : Enforce usage of slf4j over different logging frameworks

c# - NLog in .NET 4.5 控制台应用程序 : not loading Configuration

asp.net-mvc - NLog 在 IIS 上不起作用

c# - 如何根据Sqldatareader 提供的数据属性在GridView 运行时添加行、列和合并行?

c# - Linq .Select()/.SelectMany() 自动使用第二个可选参数

python - 哪个记录器在gunicorn 中输出这个?