//自定义字段写入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. 十大经典排序算法-JS篇

    http://web.jobbole.com/87968/ 虽然是JS篇,但其他编程语言(例如java)实现起来是差不多的.

  2. dom4j 输出UTF-8 XML时中文乱码

    使用DOM4J的XMLWriter输出UTF-8编码的XML文件时,出现乱码 public static void writToXml(Document document) throws IOExce ...

  3. LR接口性能测试提示Code - 60990 Error: Two Way Communication Error: Function two_way_comm_post_message / two_ (转载)

    一.在做JAVA接口性能测试时,场景在运行中出现:Code - 60990 Error: Two Way Communication Error: Function two_way_comm_post ...

  4. 基于JavaWeb实现的研究室综合系统

    代码地址如下:http://www.demodashi.com/demo/14641.html 概述 基于JavaWeb实现的研究室综合系统,功能包括研究室成员注册.登陆,后台管理,相册功能,新闻模块 ...

  5. Oracle的关于小数的使用

    整理了部分Oracle的关于小数的使用方法,如下 --round(x,[y]) 舍入到小数点右边y位的x值 ) from dual; --1.235 --trunc(x,[y])返回截尾到y位小数的x ...

  6. JavaScript Cookies,创建,获取cookies value

    什么是cookie? cookie 是存储于访问者的计算机中的变量.每当同一台计算机通过浏览器请求某个页面时,就会发送这个 cookie.你可以使用 JavaScript 来创建和取回 cookie ...

  7. 单个APP页面支持屏幕旋转

    1.info中支持所有的方向 2.APPDelega.h中添加属性 @property (nonatomic,assign) BOOL allowRotate; APPdelegate.m中实现方法 ...

  8. 简单解决XP共享连接数10限制(转)

    1.建立一个txt文件,在里面输入以下文字:net session /delete /y,并将其保存为clear session.bat文件.net session用于查看本机共享的会话详细情况,可以 ...

  9. ubuntu源列表(清华,阿里,官方,选一即可)

    Ubuntu的源列表在/etc/apt/sources.list中,替换即可 #清华的源deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial m ...

  10. Nginx对某个目录或整个网站进行登录认证的方法

    比如要对 网站目录下的 test 文件夹 进行加密认证 首先需要在opt 的主目录中 /opt/ 创建一个新文件 htpasswd此文件的书写格式是用户名:密码每行一个账户并且 密码必须使用函数 cr ...