NLog自定义字段写入数据库表,示例
//自定义字段写入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自定义字段写入数据库表,示例的更多相关文章
- NLog 自定义字段 写入 oracle
1.通过Nuget安装NLog 下载,简单入门 请参照 我刚才转的几篇文章,下面我直接贴代码 2.建表语句 create table TBL_LOG ( id ) not null, appname ...
- [转]NLog 自定义字段 写入 oracle
本文转自:http://www.cnblogs.com/skyapplezhao/p/5690695.html 1.通过Nuget安装NLog 下载,简单入门 请参照 我刚才转的几篇文章,下面我直接贴 ...
- 通过js获取前台数据向一般处理程序传递Json数据,并解析Json数据,将前台传来的Json数据写入数据库表中
摘自:http://blog.csdn.net/mazhaojuan/article/details/8592015 通过js获取前台数据向一般处理程序传递Json数据,并解析Json数据,将前台传来 ...
- Log4net 自定义字段到数据库
今天要求做个log4net自定义字段到数据库,在网上找了好多例子,都运行不成功.最后找了个国外的,很简单的就解决了. log4net它已经定义的字段有 <commandText value=&q ...
- log4net自定义字段写入SqlServer数据库 ASP.net
首先申明,本示例经过本作者亲自试验通过,可以运行 第一步 编写log4net配置文件 此处为Log.xml,该文件放在与Web.config平级的位置 <?xml version="1 ...
- 在向"带有自增字段的数据库表"中插入数据时,自定义"该自增字段"的数据
在设计数据库表的时候,经常会使用自增主键或其他自增字段.比如: DB_UserGroups表中GroupID为该表主键,并为自增字段. 但在将某字段设置自增后,想在插入数据时,人为指定自增字段的数据内 ...
- 《项目经验》--通过js获取前台数据向一般处理程序传递Json数据,并解析Json数据,将前台传来的Json数据写入数据库表中
先看一下我要实现的功能界面: 这个界面的功能在图中已有展现,课程分配(教师教授哪门课程)在之前的页面中已做好.这个页面主要实现的是授课,即给老师教授的课程分配学生.此页面实现功能的步骤已在页面 ...
- Log4net 自定义字段到数据库(二)
这种方法比第一种方法麻烦些 Log4Net.config <?xml version="1.0" encoding="utf-8" ?> <c ...
- Log4net 自定义字段 写入Oracle 使用ODP.NET Managed驱动
一.环境说明: 开发工具:vs2010 ,数据库:oracle 11g ,版本:log4net的目前最新版本1.2.13.0 : Oracle.ManagedDataAccess.dll ...
随机推荐
- tablib.Dataset()操作exl类型数据之“类方法”研究
#tablib.Dataset()操作exl类型数据之“类方法”研究 import tablib #初始化 data=tablib.Dataset() #设置列标题 data.headers=('na ...
- PHP 反射API说明
2.API概览:class Reflection { }interface Reflector { }class ReflectionException extends Exception { }cl ...
- 删除草稿信息之后 threads表的数据没有发生变化
现象描述: 无论是用_id来删除草稿信息,还是用thread_id和type来删除草稿,草稿都可以删除掉,但是threads表中的数据都没有发生变化. private void removeDraft ...
- EntityFramework 5.0 CodeFirst 教程02-删除和修改/架构改变异常的处理
-----------------------------------------------------目录--------------------------------------------- ...
- ubuntu设置自动关机
windows可以设置自动关机时间.那么ubuntu的命令是什么呢? 首先要能拿到sudo权限,还好我是在home下编译的,一路上都不用sudo,因此可以把sudo给shutdown了.呵呵 ...
- binary search tree study
今天又写了delete的部分,时间就这么被一天天地浪费了,我感到十分惋惜呀 #pragma once #include "stdio.h" struct Node { Node(i ...
- Mysql5.6 make 错误以及解决办法
1.若make出现类似错误: CMake Error: CMake was unable to find a build program corresponding to "Unix Mak ...
- 安装samba脚本
Ubuntu_samba.sh #!/bin/sh echo "Ubuntu 14.04 文件服务器--samba的安装和配置" echo "更新源列表" su ...
- POJ 2976 Dropping tests (0/1分数规划)
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4654 Accepted: 1587 De ...
- C#程序证书创建工具 (Makecert.exe)
原文地址:https://msdn.microsoft.com/zh-cn/library/bfsktky3(VS.80).aspx 证书创建工具生成仅用于测试目的的 X.509 证书.它创建用于数字 ...