首页 > 其他分享 >NLog配置文件变量

NLog配置文件变量

时间:2023-07-06 10:14:10浏览次数:31  
标签:变量 配置文件 MM callsite 线程 当前 格式 NLog

${basedir}:应用程序当前目录
${shortdate}:短日期【2022-01-06】
${longdate}:长日期【2022-01-06 14:05:20.4023】
${logger}: 记录器的名字
${event-properties:FileName}:自定义属性
${level}:记录等级【Trace,Debug,Info,Warn,Error,Fatal】
${uppercase}:转大写
${message}:调用Nlog时输入的内容
${callsite}:类名称
${callsite-linenumber}:文件行号
${hostname}:主机名
${environment} 环境变量
${exception} exception信息
${machinename} 名称
${mdc} 映射诊断
${mdlc} 异步映射诊断上下文
${ndc} 线程结构
${ndlc} 异步线程
${newline} 文字换行
${nlogdir} nlog.dll目录。
${performancecounter} 述性能计数器。
${processid} 当前进程标识符
${processinfo} 运行信息
${processname} 当前进程的名称。
${processtime} 该时间过程中格式HH:MM:ss.mmm。
${qpc} 高精度定时器,基于返回的值从queryperformancecounter(任选地)转换为秒。
${registry} 从注册表中的值。
${sequenceid} ID
${shortdate} 短时间 格式YYYY-MM-DD。
${sl-appinfo} Silverlight应用。
${specialfolder} 文件夹路径
${stacktrace} - 堆栈跟踪渲染器。
${tempdir} 临时目录中。
${threadid} 当前线程的标识符。
${threadname} 当前线程。
${ticks} 当前日期和时间。
${time} 24小时格式HH:MM:ss.mmm。
KaTeX parse error: Expected '}', got 'EOF' at end of input: {var} {var}-提供新的变量(4.1)
${windows-identity} indows线程标识信息(用户名)
Windows Form
<PackageReference Include="NLog" Version="5.2.2" />
<PackageReference Include="NLog.Windows.Forms" Version="5.2.0" />

Web Api
<PackageReference Include="NLog.Web.AspNetCore" Version="5.2.1" />

using Microsoft.Extensions.Logging;

 nlog.config

<?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" autoReload="true" internalLogLevel="Info">
  <!-- 启用.net core的核心布局渲染器 -->
  <extensions>
    <add assembly="NLog.Web.AspNetCore" />
  </extensions>
  <!-- 写入日志的目标配置 -->
  <targets>
    <!-- 调试  -->
    <target xsi:type="File" name="debug" fileName="logs/debug-${shortdate}.log" layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
    <!-- 警告  -->
    <target xsi:type="File" name="warn" fileName="logs/warn-${shortdate}.log" layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
    <!-- 错误  -->
    <target xsi:type="File" name="error" fileName="logs/error-${shortdate}.log" layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
  </targets>
  <!-- 映射规则 -->
  <rules>
    <!-- 调试  -->
    <logger name="*" minlevel="Trace" maxlevel="Debug" writeTo="debug" />
    <!--跳过不重要的微软日志-->
    <logger name="Microsoft.*" maxlevel="Info" final="true" />
    <!-- 警告  -->
    <logger name="*" minlevel="Info" maxlevel="Warn" writeTo="warn" />
    <!-- 错误  -->
    <logger name="*" minlevel="Error" maxlevel="Fatal" writeTo="error" />
  </rules>
</nlog>

 

标签:变量,配置文件,MM,callsite,线程,当前,格式,NLog
From: https://www.cnblogs.com/hofmann/p/17531311.html

相关文章

  • oracle的tnsname.ora(网络服务名配置文件)
    #tnsnames.oraNetworkConfigurationFile:E:\oracle\oracleBaseMenu\oracleMainMenu\network\admin\tnsnames.ora#GeneratedbyOracleconfigurationtools.#sqlplususername/password@service_name普通用户登录#sqlplususername/password@service_nameassys......
  • jdk配置环境变量(详细)
    java语言的产品是jdk自从2009年oracle收购的sun公司从此java的隶属于oracle公司下 1去oracle官网下载jdk  https://www.oracle.com/java/technologies/downloads/ 找到自己想要的jdk版本,下载好点击下一步安装好即可,注意自己的安装路径 ......
  • python变量
    1.变量命名变量名只能包含字母、数字和下划线。变量名不能以数字开头。变量名不能包含空格,可使用下划线python关键字和函数名不能用作变量慎用1和大写O变量名默认用小写字母表示2.多个变量同时赋值x,y,z=1,2,3print(f"{x}{y}{z}")3.常量常量名默认用全大写......
  • python数值变量
    1.整数#+-*/%2+3#乘方3**2(2+3)*42.浮点数#精度有误0.2+0.13.整数和浮点数#除的结果总是浮点数4/2#其他运算,一个整数一个浮点数,结果也是浮点数1+2.03.0**23**2.04.数中的下划线big=14_000_000_000print(big)......
  • springboot 加载自定义的属性配置文件 或者xml文件
    1、properties user.propertiesname=zhangshanage=18  2、xml Pen1.xml<?xmlversion="1.0"encoding="utf-8"?><!DOCTYPEpropertiesSYSTEM"http://java.sun.com/dtd/properties.dtd"><properties><......
  • 2. 配置文件
    1.配置文件格式我们现在启动服务器默认的端口号是8080​,访问路径可以书写为http://localhost:8080/books/1在线上环境我们还是希望将端口号改为80​,这样在访问的时候就可以不写端口号了,如下http://localhost/books/1而SpringBoot​程序如何修改呢?SpringBoot​提供了......
  • 函数 global全局变量; 局部变量;缺省参数
    #函数在函数里设置全局变量,会因为被赋值而修改x=2deffuncx():globalx#这个x是全局变量会因为函数里面被赋值而修改x=9print("thisxisinthefuncx:-->",x)funcx()print("--------------")print("thisxisinthefuncx:-->",x)'''......
  • Spring配置文件中的 context:property-placeholder标签 所有的属性以及作用
    <context:property-placeholder>是Spring框架中的一个标签,用于加载和解析属性文件,并将属性值注入到Spring容器中的bean中。以下是<context:property-placeholder>的常用属性及其作用:location:指定属性文件的位置。可以使用classpath前缀指定类路径下的属性文件,也可以使用文件系......
  • .net Core Winform 增加NLog
    nlog.config<?xmlversion="1.0"encoding="utf-8"?><nlogxmlns="http://www.nlog-project.org/schemas/NLog.xsd"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><targetsasync=&quo......
  • Spring配置文件中,bean标签下是各个子标签的作用解释
    bean标签的子标签propertyconstructor-argdescriptionlookup-methodmetaqualifierreplaced-method在Spring配置文件中,bean标签下是各个标签的作用解释:<property>:用于设置bean的属性值。它可以用于注入基本类型、引用类型或其他属性。通过指定属性名称和对应的值,可以......