- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我目前正在开发一个 webapi2 应用程序,并且正处于使用 NLog 管理我的日志的阶段。
在我的应用程序中,我以这种方式使用 LogEventInfo.Properties 字典以键值对方式登录:
thisController.LogParams.Add("ControllerName",controllerName);
thisController.LogParams.Add("ActionName", actionName);
thisController.LogParams.Add("TotalTime", actionWatch.ElapsedMilliseconds);
LogEventInfo logEvent = new LogEventInfo()
{
Message = string.IsNullOrEmpty(thisController.LogMessage)? "Finished Successfuly":thisController.LogMessage,
Level = LogLevel.Info,
TimeStamp = DateTime.Now
};
logEvent.Properties.Merge(thisController.LogParams);
logger.Log(logEvent);
一切正常,但我似乎无法找到呈现布局的方法,因此它会打印 LogEventInfo.Properties 字典中的所有键值条目。
让我们假设我的目标是一个文件,然后我必须明确提到键名,有没有办法让它显示字典的所有内容?这就是我今天的做法,在这里我只能记录我知道的条目:
<target name="f1"
xsi:type="File"
fileName="${basedir}\logs\log.txt"
maxArchiveFiles="60"
archiveNumbering="Date"
archiveDateFormat="yyyyMMdd"
archiveEvery="Day"
layout="${longdate} : ${callsite:className=true:methodName=true} : ${event-context:item=ControllerName} : ${event-context:item=ActionName} : ${event-context:item=TotalTime} : ${message}" />
最佳答案
NLog 中有一个内置的布局渲染器可用于此目的 - ${all-event-properties}。默认情况下,它以键值样式发出所有事件上下文属性,以逗号分隔。
查看文档了解更多详情 https://github.com/NLog/NLog/wiki/All-Event-Properties-Layout-Renderer
关于c# - 配置 NLog 的布局以显示所有事件上下文条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28660020/
我想更改 nlog 布局,以便显示两个条目之间的时间。这样的布局可能吗? 这是我现在的输出,如果在时间旁边有自之前进入以来经过的秒数,那就太好了。 2012-05-20 19:18:41.09
使用 NLog v4.4.12,我的 App.config 中有这个 这是我的 Variables.xml 文件内容 但是我在启动我的应
我有一个名为 的自定义布局渲染器工作 .它提供了几个项目,它们在我们的 app.config 中是这样使用的: 当
NLog 是否可以发出多行消息,以便每行都根据当前布局进行格式化?例如。 2015-12-17 11:37:38.0845 | 64 | INFO | ------------------------
我刚开始玩 nlog,注意到 nlog.xml 文件与 nlog.dll 一起被带到了应用程序的输出文件夹中。我不太清楚该文件的用途以及我是否应该将它作为我的应用程序安装的一部分或可以安全地删除它。有
是否可以/容易使用 Rhino Mocks 或类似方法模拟 NLog 日志方法? 最佳答案 使用 Nuget:install-package NLog.Interface 然后:ILogger log
目标: 当我打电话时Logger.Error("some message", e) ,其中 e是一些异常对象,它只记录消息,不记录异常信息。我需要它来输出异常消息和堆栈跟踪。任何想法我做
在生产环境中更改 nLog 日志记录级别的最佳做法是什么。我可以更改它的唯一方法是修改 NLog.config 文件,然后回收应用程序池。应该这样吗? 谢谢, 克里斯 最佳答案 如果你想改变日志配置而
我已经创建了一个通用实现 ILogger 并在这个包装器中实现了 NLog 实现方法。我的问题是我在我的解决方案中为整个 namspace 启用了错误严重性,但我还希望对“Employee”命名空间下
我在 NLog.config 中配置了两条规则: 我正在尝试使用以下代码写入第一个: LogEventInfo eventInfo = new LogEventInfo(); eventInfo.
我正在尝试将一堆应用程序使用的现有日志记录库转换为使用 NLog。现有的日志记录代码没有间接性,日志记录调用直接从调用者到 Web 服务调用。现有的日志记录代码是作为静态单例实现的。我需要以这样一种方
我有一个泛型类: public class GenericClass { private static readonly Logger Logger = LogManager.GetCurre
在我看来,NLog 中的内置日期格式没有正确包含时区。我们需要用尾随 Z 记录 UTC 时间,以便 Splunk 知道本地时间是什么,例如: {日期:universalTime=true:format
我们提供了一个用于日志记录的框架程序集,它在内部使用 nlog。我们还提供了一个嵌入式 nlog 配置作为我们程序集中的资源,并在启动时读取它(包装器中的静态构造函数,它使用 XmlLoggingCo
我这样编码: private static readonly ILogger Logger = LogManager.GetCurrentClassLogger(); public MyClass()
现在我这样做 LogManager.DisableLogging(); 但这需要再次部署我的代码,如何从 nlog 配置文件中禁用登录。 最佳答案 关于nlog - 从 Nlog.config 发
我想弄清楚如何阻止 NLog 替换我正在记录的字符串中的换行符。我希望输出包含所有换行符,而不是将整个输出放在一行中。 有人可以帮忙吗? 配置: 代码
作为从 NLog 切换到 Serilog 的一个步骤,我想重定向 NLog 的 LogManager.GetLogger(name) 的标准调用的标准接线,以桥接任何记录到 NLog 的代码,以便立即
为此,我需要一份详细/分步指南。我已经阅读了简要指南 ( example here ) 并下载了示例代码,但我仍然无法弄清楚如何使用 Nlog 登录到 CloudWatch。 当我在 NLog.con
我将 NLog 错误电子邮件文本的内容放入一个文件中,并使用 FileContents 渲染器进行渲染。如果布局渲染器产生空字符串,我想做的是隐藏 html 输出的某些部分 Request ticke
我是一名优秀的程序员,十分优秀!