NLog Layout Renderers

【小作业】为NLog自定义LayoutRenderer 长话短说   前文《解剖HttpClientFactory,自由扩展HttpMessageHandler》主要想讲如何扩展HttpMessageHandler, 示例为在每个Http请求中的日志中显示TraceId, 现在来完成课后的小作业: 将TraceId显示到Nlog的LayoutRenderer上。 本次重新实现一个流畅简单的 LoggingHttpMessageHandler,... 阅读详情

转自 https://nlog-project.org/config/?tab=layout-renderers

  • ${cached} - Applies caching to another layout output.
  • ${exception} - Exception information provided through a call to one of the Logger methods
  • ${level} - The log level (e.g. ERROR, DEBUG) or level ordinal (number)
  • ${literal} - A string literal. (text) - useful to escape brackets
  • ${logger} - The logger name. GetLogger, GetCurrentClassLogger etc
  • ${message} - The (formatted) log message.
  • ${newline} - A newline literal.
  • ${onexception} - Only outputs the inner layout when exception has been defined for log message.
  • ${var} - Render variable

Callsite and stacktraces

  • ${callsite} - The call site (class name, method name and source information)
  • ${callsite-linenumber} - The call site source line number.
  • ${stacktrace} - Render the Stack trace

Conditions

  • ${when} - Only outputs the inner layout when the specified condition has been met
  • ${whenempty} - Outputs alternative layout when the inner layout produces empty result.

Context information

  • ${all-event-properties} - Log all event context data.
  • ${event-context} - Log event properties data replaced with ${event-properties}
  • ${event-properties} - Log event properties data - rename of ${event-context}
  • ${gdc} - Global Diagnostic Context item. Dictionary structure to hold per-application-instance values.
  • ${install-context} - Installation parameter (passed to InstallNLogConfig).
  • ${mdc} - Mapped Diagnostics Context - a thread-local structure.
  • ${mdlc} - Async Mapped Diagnostics Context - a thread-local structure. Async version of the MDC
  • ${ndc} - Nested Diagnostics Context - a thread-local structure.
  • ${ndlc} - Async Nested Diagnostics Context - thread-local structure.

Counters

  • ${counter} - A counter value (increases on each layout rendering)
  • ${guid} - Globally-unique identifier(GUID).
  • ${sequenceid} - The log sequence id

Date and time

  • ${date} - Current date and time.
  • ${longdate} - The date and time in a long, sortable format yyyy-MM-dd HH:mm:ss.ffff.
  • ${shortdate} - The short date in a sortable format yyyy-MM-dd.
  • ${ticks} - The Ticks value of current date and time.
  • ${time} - The time in a 24-hour, sortable format HH:mm:ss.mmm.

Encoding and string transformations

  • ${wrapline} - Wraps the result of another layout output at specified line length.
  • ${json-encode} - Escapes output of another layout using JSON rules.
  • ${lowercase} - Converts the result of another layout output to lower case.
  • ${pad} - Applies padding to another layout output.
  • ${replace} - Replaces a string in the output of another layout with another string. Optional with regex
  • ${replace-newlines} - Replaces newline characters with another string.
  • ${rot13} - Decodes text "encrypted"with ROT-13.
  • ${trim-whitespace} - Trims the whitespace from the result of another layout renderer.
  • ${uppercase} - Converts the result of another layout output to upper case.
  • ${url-encode} - Encodes the result of another layout output for use with URLs.
  • ${xml} - Converts to fixed XML format NLog.XML External
  • ${xml-encode} - Converts the result of another layout output to be XML-compliant.

Environment and config files

  • ${appsetting} - App config setting from .config file NLog.Extended
  • ${configsetting} - Value from the appsettings.json or other configuration in ASP.NET Core & .NET Core NLog.Extensions.LoggingNLog.Extensions.HostingNLog.Web.AspNetCore
  • ${environment} - The environment variable. (e.g PATH, OSVersion)
  • ${gc} - The information about the garbage collector.
  • ${registry} - A value from the Windows Registry.

Files and directories

  • ${basedir} - The current application domain’s base directory.
  • ${currentdir} - The current working directory of the application.
  • ${file-contents} - Renders contents of the specified file.
  • ${filesystem-normalize} - Filters characters not allowed in the file names by replacing them with safe character.
  • ${nlogdir} - The directory where NLog.dll is located.
  • ${specialfolder} - System special folder path (includes My Documents, My Music, Program Files, Desktop, and more).
  • ${tempdir} - A temporary directory.

Identity

  • ${identity} - Thread identity information (name and authentication information).
  • ${windows-identity} - Thread Windows identity information (username)
  • ${windows-identity} - Thread Windows identity information (username) Nlog.WindowsIdentity

Integrations

  • ${gelf} - Converts log to GELF format NLog.GelfLayout External
  • ${log4jxmlevent} - XML event description compatible with log4j, Chainsaw and NLogViewer.

Processes, threads and assemblies

  • ${appdomain} - Current app domain.
  • ${assembly-version} - The version of the executable in the default application domain.
  • ${hostname} - The host name of the computer that the process is running on.
  • ${machinename} - The machine name that the process is running on.
  • ${processid} - The identifier of the current process.
  • ${processinfo} - The information about the running process. e.g. StartTime, PagedMemorySize
  • ${processname} - The name of the current process.
  • ${processtime} - The process time in format HH:mm:ss.mmm.
  • ${threadid} - The identifier of the current thread.
  • ${threadname} - The name of the current thread.

Silverlight

  • ${document-uri} - URI of the HTML page which hosts the current Silverlight application.
  • ${sl-appinfo} - Information about Silverlight application.

Trace and debugging

  • ${activityid} - Puts into log a System.Diagnostics trace correlation id.

  • ${performancecounter} - The performance counter.

  • ${qpc} - High precision timer, based on the value returned from QueryPerformanceCounter.
    Web, ASP.NET and ASP.NET Core

  • ${aspnet-application} - ASP.NET Application variable. NLog.Web

  • ${aspnet-item} - ASP.NET HttpContext item variable. NLog.WebNLog.Web.AspNetCore

  • ${aspnet-mvc-action} - ASP.NET MVC action name NLog.WebNLog.Web.AspNetCore

  • ${aspnet-mvc-controller} - ASP.NET MVC controller name NLog.WebNLog.Web.AspNetCore

  • ${aspnet-request} - ASP.NET Request variable. NLog.WebNLog.Web.AspNetCore

  • ${aspnet-request-cookie} - ASP.NET Request cookie content. NLog.WebNLog.Web.AspNetCore

  • ${aspnet-request-form} - ASP.NET Request form content. NLog.WebNLog.Web.AspNetCore

  • ${aspnet-request-host} - ASP.NET Request host. NLog.WebNLog.Web.AspNetCore

  • ${aspnet-request-ip} - Client IP. NLog.WebNLog.Web.AspNetCore

  • ${aspnet-request-method} - ASP.NET Request method (GET, POST etc). NLog.WebNLog.Web.AspNetCore

  • ${aspnet-request-querystring} - ASP.NET Request querystring. NLog.WebNLog.Web.AspNetCore

  • ${aspnet-request-referrer} - ASP.NET Request referrer. NLog.WebNLog.Web.AspNetCore

  • ${aspnet-request-url} - ASP.NET Request URL. NLog.WebNLog.Web.AspNetCore

  • ${aspnet-request-useragent} - ASP.NET Request useragent. NLog.WebNLog.Web.AspNetCore

  • ${aspnet-session} - ASP.NET Session variable. NLog.WebNLog.Web.AspNetCore

  • ${aspnet-sessionid} - ASP.NET Session ID variable. NLog.WebNLog.Web.AspNetCore

  • ${aspnet-traceidentifier} - ASP.NET trace identifier NLog.WebNLog.Web.AspNetCore

  • ${aspnet-user-authtype} - ASP.NET User auth. NLog.WebNLog.Web.AspNetCore

  • ${aspnet-user-identity} - ASP.NET User variable. NLog.WebNLog.Web.AspNetCore

  • ${aspnet-user-isauthenticated} - ASP.NET User authenticated? NLog.WebNLog.Web.AspNetCore

  • ${aspnet-appbasepath} - ASP.NET Application base path (Content Root) NLog.WebNLog.Web.AspNetCore

  • ${aspnet-environment} - ASP.NET Environment name NLog.Web.AspNetCore

  • ${aspnet-request-contenttype} - ASP.NET Content-Type header (Ex. application/json) NLog.Web.AspNetCore

  • ${aspnet-webrootpath} - ASP.NET Web root path (wwwroot) NLog.WebNLog.Web.AspNetCore

  • ${iis-site-name} - IIS site name. NLog.WebNLog.Web.AspNetCore

另外传递自定义值到Layout 可以通过- ${event-properties} 来获取
Passing Custom Values to a Layout

Even though the layout renderers provide many pre-defined values, you may need to pass application specific values to your Layouts. You can pass your own values in code by adding custom properties to the event. You then retrieve the value using the

  • ${event-properties} renderer. See the documentation for the
  • ${event-properties} for an example
SSIM图像质量评价Matlab实现:公式、代码与调参 图像质量评价是压缩、超分、去噪等任务中衡量图像保真度的基础环节。传统MSE/PSNR逐像素做差,对结构、纹理和边缘退化不敏感;SSIM则将局部亮度、对比度与结构项统一到统计框架中,通过均值、方差和协方差计算结构相似度,更贴近人眼对结构信息的感知。其技术价值是提供可批量、可复现的客观分数,并能生成SSIM映射图定位局部失真。在图像压缩、超分辨率重建、去噪和生成模型对比中,SSIM常与PSNR搭配使用。落到Matlab工程实践,关键在于高斯窗、filter2向量化、K1/K2/L参数与MSSIM批量评估的正确实 阅读详情

相关推荐

闲人闲谈PS之十二——WBS-BOM在装备制造项目中的实战解析

本文深入解析了WBS-BOM在装备制造项目中的核心应用。针对按订单设计/生产的行业痛点,WBS-BOM作为项目专属物料清单,完美连接SAP PS与PP模块,确保MRP能基于项目进行精准物料需求计算,实现从设计到生产的全链路项目化跟踪与管理。

weixin_29284885的博客 414

NLog 配置文件中布局渲染器(layout renderers)

NLog 配置文件中,布局渲染器(layout renderers)是一种机制,用于在日志消息中插入动态内容或格式化信息。它们允许您将变量、属性、日期时间信息等添加到日志消息中,以便更详细地记录和分析日志。布局渲染器是在${}中包含的占位符,会在运行时替换为实际值。

weixin_42098295的博客 1322

NFT图片批量合成及稀有度计算工具

一、制作背景 -当前NFT作品制作的大多方式都是使用部件拼接的形式,然后从大量的可能性结果取优; 二、解决问题 拼接合成的组合数量十分巨大,手工合成费时费力; 合成中对各个部件的使用次数不容易控制,部位出现的概率对作品的稀有度及评分影响较大; 对于生成的作品各个部位的信息(包括来源和使用率)统计繁琐,不利于对作品的介绍中体现; 三、程序功能介绍 1、功能自定义部位稀有度批量合成NFT作品 步骤一:创建各个合成部件文件夹,将图片放到文件夹内 步骤二:软件上设置各个部件对于的图片文件夹及出现的概率 步骤二

Keeping111的博客 4651

扩展Nlog Layout Renderer原理、Demo、 工具下载

  我们可以通过修改NLog配置文件来控制日志输出格式,但是有时候我们会有这样的需求:我要把UserID OrderID也记录下来,我们可以像使用${date}${message}一样写${UserID} ${OrderID}么?答案是可以的,只需要写一个扩展。我们讲分析实现原理,给出代码示例,演示一下怎么在程序中应用,并提供一个生成Layout Renderer扩展代码的小工具。

坚强2002@CSDN 1307

信息学奥赛一本通C++语言——1013:温度表达转化

【题目描述】 利用公式 C=5×(F−32)÷9 (其中C表示摄氏温度,F表示华氏温度)进行计算转化,输入华氏温度F,输出摄氏温度C,要求精确到小数点后5位。 【输入】 输入一行,包含一个实数F,表示华氏温度。(F≥−459.67) 【输出】 输出一行,包含一个实数,表示对应的摄氏温度,要求精确到小数点后5位。 【输入样例】 41 【输出样例】 5.00000 代码 #include<cst...

子航OIer 1321

CHIP-Seq数据分析流程

文章目录CHIP-Seq数据分析流程相关软件安装数据下载将SRA转化为fastq文件数据质控,过滤数据质控然后进行质控,过滤低质量reads,去接头比对下载小鼠参考基因组的索引和注释文件比对sam文件转bam为bam文件建立索引载入IGV查看用MACS call peak安装MACS结果注释与可视化 CHIP-Seq数据分析流程 相关软件安装 所需要的软件有sratoolkit, fastqc,bowtie2,samtools,macs2,htseq-count,bedtools和前面RNA-seq数据分析

bio_meimei的博客 8799

ASP.NET Core使用Elasticsearch记录NLog日志

ASP.NET Core使用Elasticsearch记录NLog日志 1、新建一个 ASP.NET Core项目 2、安装Nuge包 运行:Install-Package NLog.Web.AspNetCore 运行:Install-Package NLog 运行:Install-package NLog.Targets.ElasticSearch 3、编...

weixin_34006965的博客 431

STM32 stack_size和heap_size大小设置的意义

在使用STM32编程时,一般情况下我们不会关注堆栈空间的大小,因为在STM32的启动文件中,已经帮我们预先设置好了堆栈空间的大小。如下图所示的启动代码中,Stack栈的大小为:0x400(1024Byte),Heap堆的大小为:0x200(512Byte)。 1、若工程中使用的局部变量较多,定义的数据长度较大时,若不调整栈的空间大小,则会导致程序出现栈溢出,程序运行结果与预期的不符或程序跑飞。这时我们就需要手动的调整栈的大小。 2、当工程中使用了malloc动态分配内存空间时,这时分配.......

zxm8513CSDN博客 3万+

. netCore NLog 自定义Render总结

Nlog在格式化输出日志过程中,如果变量不够用,则需要自定义变量实现。具体自定义变量也很简单,只需添加自定义LayOutRenderer即可。具体实现步骤如下:

weixin_46681279的博客 830

手把手教你学Simulink——基于经典滤波器设计的场景:低通滤波器(LPF)的设计与频率响应仿真

滤波器是信号处理领域中非常重要的组件,用于去除不需要的频率成分或者提取有用的频率信息。低通滤波器(Low-Pass Filter, LPF)允许低于某个特定截止频率的信号通过,同时衰减高于该截止频率的信号。在本教程中,我们将学习如何使用设计一个简单的模拟低通滤波器,并对其频率响应进行仿真分析。本文介绍了如何使用设计一个简单的模拟低通滤波器,并通过仿真展示了其应用效果。通过这样的实践,您不仅能够加深对滤波器工作原理的理解,还能掌握利用Simulink进行滤波器设计与仿真的基本技能。

MHD0815的博客 5728

1、机器学习在环境科学中的应用与经典数据分析基础

本文介绍了机器学习在环境科学中的广泛应用,包括卫星遥感、气候预测、空气质量预报等领域,并系统回顾了经典数据分析的基本概念,如期望、方差、协方差和相关性及其显著性检验。同时,文章阐述了贝叶斯定理、判别函数与分类、聚类分析等方法的原理与应用,强调了经典统计方法与机器学习技术的互补关系。最后展望了未来环境科学中数据分析的发展方向,强调多学科融合与方法创新的重要性。

stone的博客 147

[转]NLog Layout Renderers ${}

https://github.com/nlog/NLog/wiki/Layout-Renderers Layout renderers are template macros that are used in Layouts. NLog supports creating custom layout renderers. For more information, see: Extending...

weixin_33856370的博客 131

零基础做完YOLOv8船只检测系统:HRSC2016数据集 + 完整UI,稳过答辩

亲爱的同学,通过这篇教程,你已经掌握了“基于YOLOv8的HRSC2016微小船只检测系统”从数据集处理、模型训练到Tkinter界面开发的全流程。这个课题既贴合“海事智能化”的产业战略,又涵盖了“目标检测、深度学习、界面开发”等多个毕设评分点,非常适合作为计算机或海事工程专业的毕业设计。在实践中,你可能会遇到“海面背景复杂导致船只漏检”“微小船只识别精度不足”“UI与模型推理同步卡顿”等挑战——别担心,这些都是技术成长的必经之路。

FJN110的博客 113

【NLog】.net core 使用NLog将日志存入MongoDB

1、安装Nuget包: NLog; NLog.Web.AspNetCore; NLog.Mongo; NLog.WindowsIdentity; NLog.WindowsIdentity不一定需要,如果运行时报异常(如果配置文件中throwException设置为false,不会报异常):找不到“windows-identity”就需要安装这个包。 2、配置文件: &amp;lt;?xml version...

tang604578896的博客 2118

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

nlog官方帮助_NLog类库使用探索——详解配置

1 配置文件的位置(Configuration file locations)通过在启动的时候对一些常用目录的扫描,NLog会尝试使用找到的配置信息进行自动的自我配置。1.1 单独的*.exe客户端单独的客户端,NLog将在以下目录搜索配置信息:标准的程序配置文件(通常为 程序名.exe.config)程序目录下的程序名.exe.nlog文件程序目录下的NLog.config文件NLog.dll所...

weixin_39587822的博客 498

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

C#中使用NLOG步骤

步骤1:项目中加入NLOG库打开“工具”->“NuGet包管理器”,搜索“NLOG”,安装“NLog”和“NLog.Windows.Forms”两个库,如下图所示步骤2:添加引用具体路径见下图 步骤3:增加NLog.config文件和NLog.xsd文件可以从其它位置上COPY过来,也可以自己编写;NLog.config文件为LOG的配置文件,具体语法和意义见我的另一篇博文说明;NLog.xsd是语法文件,不用改动步骤4:在程序中增加引用 步骤5:设置config文件复制到输出目录 步骤6:使用 得到

nixoncheng的博客 4128

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

NLog Configuration options

来源:https://nlog-project.org/config/?

weixin_46681279的博客 467

转:NLog 自定义日志内容,写日志到数据库;修改Nlog.config不起作用的原因

转:http://www.cnblogs.com/tider1999/p/4308440.html NLog的安装请百度,我安装的是3.2。NLog可以向文件,数据库,邮件等写日志,想了解请百度,这里讲怎么写入数据库,及常常会遇到的问题: 1、layout render    NLog内置了很多日志内容格式,样子就是${longdate}之类的,详见:https://github.com/N...

weixin_33932129的博客 647

空调省电真相:从能效标签到实战省电的四层逻辑与TCL真省电Pro二代深度解析

在能源管理与家电智能化领域,能效优化始终是核心议题。其基本原理在于通过提升能源转换效率与智能控制算法,在满足功能需求的前提下最小化能耗。从技术价值看,这不仅关乎用户电费支出,更是实现可持续能源利用的关键实践。具体到应用场景,家用空调的能耗表现受到硬件性能、系统算法、安装环境与使用习惯等多重因素影响。本文围绕空调省电这一主题,深入剖析了从实验室能效到用户实际体验的四层逻辑体系。通过拆解TCL真省电Pro二代空调所搭载的智能光感、智能风感等核心技术,并结合变频压缩机与系统控制算法,揭示了其宣称的节能承诺背后的技

weixin_34109408的博客 393

NLog 自定义日志内容,写日志到数据库;修改Nlog.config不起作用的原因

NLog的安装请百度,我安装的是3.2。NLog可以向文件,数据库,邮件等写日志,想了解请百度,这里讲怎么写入数据库,及常常会遇到的问题: 1、layout render   NLog内置了很多日志内容格式,样子就是${longdate}之类的,详见:https://github.com/NLog/NLog/wiki/Layout-Renderers 2、如果我们要自定义日志: &...

weixin_34413357的博客 635

Layout Renderers

Layout Renderers NLog package ${activityid} - Puts into log a System.Diagnostics trace correlation id. ${all-event-properties} - Log all event context data. ${appdomain} - Current app domain. ${asse...

weixin_34049032的博客 255

NLog日志文件归档与清理配置实战:解决磁盘空间与运维难题

日志管理是系统可观测性的基础环节,其核心原理在于通过合理的输出策略控制日志文件的生成与生命周期。在.NET技术栈中,NLog作为高性能日志框架,通过归档与保留机制实现技术价值:防止日志文件无限增长导致的磁盘空间耗尽,并提升日志查询与运维效率。应用场景涵盖从单机应用到分布式系统,开发者通过配置archiveAboveSize控制单个文件大小,结合maxArchiveFiles限制历史文件数量,从而自然收敛到本文主题——构建整洁高效的日志系统。本文深入解析NLog文件目标的配置策略,涵盖异步写入性能优化与多进程

weixin_30279315的博客 355

NLOG的使用

c# NLOG使用随记

nixoncheng的博客 1118

nlog官方帮助_最有用的NLOG配置

What are the best or most useful configurations for logging with NLog? (These can be simple or complex, as long as they're useful.)I'm thinking of examples like automatically rolling over log files at...

weixin_39593961的博客 203

NLog自定义Layout Renderer

更多精彩内容请关注我们长话短说前文《解剖HttpClientFactory,自由扩展HttpMessageHandler》主要讲如何为HttpClientFactory自定义HttpMe...

dotNET跨平台 958
上一篇: asp.net core 动态增加定时任务
下一篇: Nlog 在.net core中 记录请求上下文的标识符
走错路的程序员
博客等级 码龄19年 1257粉丝 507原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值