NLog Layout Renderers

转自 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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<?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" xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd" autoReload="true" throwExceptions="false" internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log"> <!-- optional, add some variables https://github.com/nlog/NLog/wiki/Configuration-file#variables --> <variable name="myvar" value="myvalue"/> <!-- See https://github.com/nlog/nlog/wiki/Configuration-file for information on customizing logging rules and outputs. --> <targets> <!-- add your targets here See https://github.com/nlog/NLog/wiki/Targets for possible targets. See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers. --> <!-- Write events to a file with the date in the filename. <target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log" layout="${longdate} ${uppercase:${level}} ${message}" /> --> <target xsi:type="File" name="f" fileName="logs/${shortdate}.log" archiveFileName="logs/archive.{#}.log" archiveEvery="Day" archiveNumbering="Rolling" maxArchiveFiles="30" concurrentWrites="true" keepFileOpen="false" encoding="utf-8"> <layout xsi:type="CsvLayout" delimiter="auto" withHeader="true" > <column name="time" layout="${longdate:universalTime=false}" /> <column name="threadid" layout="${threadid}"/> <column name="level" layout="${level:upperCase=true}"/> <column name="callsite" layout="${callsite:includeSourcePath=true}" /> <column name="message" layout="${message}" /> <column name="stacktrace" layout="${callsite:includeSourcePath=true}" /> <column name="exception" layout="${exception:format=ToString}"/> </layout> </target> <target xsi:type="File" name="c" layout="${threadid} ${uppercase:${level}} ${message} ${callsite} ${exception:format=tostring}" /> </targets> <rules> <!-- add your logging rules here --> <!-- Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f" <logger name="*" minlevel="Debug" writeTo="f" /> --> <logger name="*" writeTo="f,c" /> </rules> </nlog>NLog这个配置给我怎么加注释说明
06-04

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值