//自定义字段写入NLog日志

private void saveNLog(InvokeLogModel model)
{
LogEventInfo ei = new LogEventInfo();
ei.Properties["InvokeResult"] = model.InvokeResult;
ei.Properties["RequestUrl"] = model.RequestUrl;
ei.Properties["MethodName"] = model.MethodName;
ei.Properties["InvokeUserName"] = model.InvokeUserName;
ei.Properties["InputJson"] = model.InputJson;
ei.Properties["OutputJson"] = model.OutputJson;
ei.Properties["BeginTime"] = model.BeginTime;
ei.Properties["EndTime"] = model.EndTime;
//ei.Message = "my test log message";
ei.Level = LogLevel.Info;
nlogger.Log(ei);
} //配置读取自定义字段 <?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"
internalLogLevel="Trace"
internalLogFile="C:/internalLog.txt">
<targets async="true">
<target xsi:type="File" name="SimpleDemoFile" fileName="${basedir}/logs/${shortdate}.txt" layout="${longdate} | ${level} | ${message} ${onexception:${exception:format=tostring} ${newline} ${stacktrace} ${newline}" encoding="UTF-8"/>
<target xsi:type="Console" name="Console11" layout="${message}" encoding="UTF-8"/>
<target type="Database" name="database" connectionstring="Server=.;Database=LogDB;Uid=de;Pwd=de;">
<commandText>
INSERT INTO [LogInfo].[InterfaceBeInvokedLog]
([LogLevel]
,[InvokeResult]
,[InvokeUserName]
,[RequestUrl]
,[MethodName]
,[InputJson]
,[OutputJson]
,[BeginTime]
,[EndTime]
)
values (@LogLevel, @InvokeResult, @InvokeUserName, @RequestUrl, @MethodName, @InputJson, @OutputJson, @BeginTime, @EndTime);
</commandText>
<parameter name="@LogLevel" layout="${level}"/>
<parameter name="@InvokeResult" layout="${event-context:item=InvokeResult}"/>
<parameter name="@InvokeUserName" layout="${event-context:item=InvokeUserName}"/>
<parameter name="@RequestUrl" layout="${event-context:item=RequestUrl}"/>
<parameter name="@MethodName" layout="${event-context:item=MethodName}"/>
<parameter name="@InputJson" layout="${event-context:item=InputJson}"/>
<parameter name="@OutputJson" layout="${event-context:item=OutputJson}"/>
<parameter name="@BeginTime" layout="${event-context:item=BeginTime}"/>
<parameter name="@EndTime" layout="${event-context:item=EndTime}"/>
</target>
</targets>
<rules>
<logger name="*" minLevel="Info" writeTo="SimpleDemoFile"/>
<logger name="*" level="Info" writeTo="Console11,database"/>
</rules>
</nlog>

NLog自定义字段写入数据库表,示例的更多相关文章

  1. NLog 自定义字段 写入 oracle

    1.通过Nuget安装NLog 下载,简单入门 请参照 我刚才转的几篇文章,下面我直接贴代码 2.建表语句 create table TBL_LOG ( id ) not null, appname ...

  2. [转]NLog 自定义字段 写入 oracle

    本文转自:http://www.cnblogs.com/skyapplezhao/p/5690695.html 1.通过Nuget安装NLog 下载,简单入门 请参照 我刚才转的几篇文章,下面我直接贴 ...

  3. 通过js获取前台数据向一般处理程序传递Json数据,并解析Json数据,将前台传来的Json数据写入数据库表中

    摘自:http://blog.csdn.net/mazhaojuan/article/details/8592015 通过js获取前台数据向一般处理程序传递Json数据,并解析Json数据,将前台传来 ...

  4. Log4net 自定义字段到数据库

    今天要求做个log4net自定义字段到数据库,在网上找了好多例子,都运行不成功.最后找了个国外的,很简单的就解决了. log4net它已经定义的字段有 <commandText value=&q ...

  5. log4net自定义字段写入SqlServer数据库 ASP.net

    首先申明,本示例经过本作者亲自试验通过,可以运行 第一步 编写log4net配置文件 此处为Log.xml,该文件放在与Web.config平级的位置 <?xml version="1 ...

  6. 在向"带有自增字段的数据库表"中插入数据时,自定义"该自增字段"的数据

    在设计数据库表的时候,经常会使用自增主键或其他自增字段.比如: DB_UserGroups表中GroupID为该表主键,并为自增字段. 但在将某字段设置自增后,想在插入数据时,人为指定自增字段的数据内 ...

  7. 《项目经验》--通过js获取前台数据向一般处理程序传递Json数据,并解析Json数据,将前台传来的Json数据写入数据库表中

      先看一下我要实现的功能界面:   这个界面的功能在图中已有展现,课程分配(教师教授哪门课程)在之前的页面中已做好.这个页面主要实现的是授课,即给老师教授的课程分配学生.此页面实现功能的步骤已在页面 ...

  8. Log4net 自定义字段到数据库(二)

    这种方法比第一种方法麻烦些 Log4Net.config <?xml version="1.0" encoding="utf-8" ?> <c ...

  9. Log4net 自定义字段 写入Oracle 使用ODP.NET Managed驱动

    一.环境说明: 开发工具:vs2010   ,数据库:oracle 11g ,版本:log4net的目前最新版本1.2.13.0    :  Oracle.ManagedDataAccess.dll ...

随机推荐

  1. 【Shell】Linux的判断表达式:-d,-f,-e等

    文件比较运算符 表达式         说明                            案例 -e filename    如果filename存在,则为真        [ –e /et ...

  2. IF函数

    语法:IF(logical_test,value_if_true,value_if_false) logical_test:表示计算结果为 TRUE 或 FALSE 的任意值或表达式 value_if ...

  3. excel 如何快速实现绝对引用

    当函数输入完成并框选数据区域后,变成如上效果时,按“F4键”即可

  4. python必须要安装的库

    1.requests 2.lxml 3.Django 4.BeautifulSoup 5.PyMySQL-0.7.0 (适用于python3) 6.图片处理PIL

  5. 转 php安装错误configure: error: Please reinstall the libcurl distribu

    今天配置一台server的php支持curl的时候, 出现如下报错 checking for cURL in default path... not foundconfigure: error: Pl ...

  6. Memcacher win7 安装测试

    1.下载memcache 的windows 稳定版,解压放某个盘下面,比如在H:/wamp/www/php api/memcache: 2.在终端(即cmd 命令界面)下,输入安装命令 :H:/wam ...

  7. 敏捷开发与Scrum

    敏捷开发以用户的需求进化为核心,采用迭代.循序渐进的方法进行软件开发.在敏捷开发中,软件项目在构建初期被切分成多个子项目,各个子项目的成果都经过测试,具备可视.可集成和可运行使用的特征.换言之,就是把 ...

  8. 微信小程序开发学习资料

    作者:初雪链接:https://www.zhihu.com/question/50907897/answer/128494332来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...

  9. intellij idea强制更新索引

    intellij idea使用时间长了,许多包安了又卸.卸了又安,导致索引文件有些不正常. 删除~/.Intellij Idea/下的index和cache即可彻底更新.

  10. C语言中的随意跳转

    C语言中有一个很不常用的头文件:setjmp.h. 这个头文件是C语言底层实现的,不像math.h里面的函数都是纯C语言实现的. setjmp.h包含两个函数: longjmp 跳转到某个位置 set ...