//自定义字段写入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. 要想找出以“y”结尾的名字

    要想找出以“y”结尾的名字:mysql> SELECT * FROM pet WHERE name LIKE '%y'“_”:匹配任何单个字符“%”:匹配任意数目字符(包括零字符)

  2. 微软微服务架构eShopOnContainers

    为了推广.Net Core,微软为我们提供了一个开源Demo-eShopOnContainers,这是一个使用Net Core框架开发的,跨平台(几乎涵盖了所有平台,windows.mac.linux ...

  3. 使用u盘安装os x系统

    从 App Store 下载 OS X 安装器 请执行以下步骤下载要安装的 OS X 版本. 1. 从 Apple 菜单中,选取“App Store”. 2. 按住 Option 键并点按“已购项目” ...

  4. fedora开机出现There is a problem with the configuration server. (/usr/libexec/gconf-sanity-check-2 exited with status 256)

    Install problem!The configuration defaults for GNOME Power Manager have not been installed correctly ...

  5. ubuntu设置自动关机

    windows可以设置自动关机时间.那么ubuntu的命令是什么呢?   首先要能拿到sudo权限,还好我是在home下编译的,一路上都不用sudo,因此可以把sudo给shutdown了.呵呵   ...

  6. Android轻量级ORM框架ActiveAndroid入门教程(转)

    注:没有找到出处,如有侵犯,请告知 开始ActiveAndroid神奇之旅: 在AndroidManifest.xml中我们需要添加这两个 AA_DB_NAME (数据库名称,这个name不能改,但是 ...

  7. POJ 3253 Fence Repair (哈夫曼树)

    Fence Repair Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19660   Accepted: 6236 Des ...

  8. POJ 1486 Sorting Slides (KM)

    Sorting Slides Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2831   Accepted: 1076 De ...

  9. React(0.13) 定义一个多选的组件

    <!DOCTYPE html> <html> <head> <title>React JS</title> <script src=& ...

  10. hadoop下载地址

    hadoop下载地址 http://mirror.bit.edu.cn/apache/hadoop/common/ hadoop下载地址