<sdt id="2356991" sdtdocpart="t" docparttype="Table of Contents" docpartunique="t"><p style="margin: 24pt 0cm 0pt" class="MsoTocHeading"><strong><font size="5"><font color="#365f91"><span style="font-family: 宋体; mso-ascii-font-family: Cambria; mso-ascii-theme-font: major-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: major-fareast; mso-hansi-font-family: Cambria; mso-hansi-theme-font: major-latin; mso-ansi-language: ZH-CN">目录</span><span style="line-height: 115%; color: windowtext; font-size: 10.5pt; font-weight: normal; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: ZH-CN"><sdtpr></sdtpr></span></font></font></strong></p> <p style="margin: 0cm 0cm 0pt; tab-stops: right dotted 414.8pt" class="MsoToc1"><span lang="EN-US"><a href="#_Toc260995986" target="_blank"><span style="mso-no-proof: yes"><font face="Calibri">1 </font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-no-proof: yes" lang="EN-US"><span lang="EN-US">使用技术以及外部框架</span></span><font face="Calibri"><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen"><span style="mso-tab-count: 1 dotted">... </span></span><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen">1</span></font></a></span><span style="mso-bidi-font-size: 11.0pt; mso-no-proof: yes" lang="EN-US"><p></p></span></p> <p style="margin: 0cm 0cm 0pt; tab-stops: right dotted 414.8pt" class="MsoToc1"><span lang="EN-US"><a href="#_Toc260995987" target="_blank"><span style="mso-no-proof: yes"><font face="Calibri">2 </font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-no-proof: yes" lang="EN-US"><span lang="EN-US">详细描述</span></span><font face="Calibri"><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen"><span style="mso-tab-count: 1 dotted">... </span></span><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen">1</span></font></a></span><span style="mso-bidi-font-size: 11.0pt; mso-no-proof: yes" lang="EN-US"><p></p></span></p> <p style="margin: 0cm 0cm 0pt 21pt; tab-stops: right dotted 414.8pt" class="MsoToc2"><span lang="EN-US"><a href="#_Toc260995988" target="_blank"><span style="mso-no-proof: yes"><font face="Calibri">2.1</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-no-proof: yes" lang="EN-US"><span lang="EN-US">概况</span></span><font face="Calibri"><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen"><span style="mso-tab-count: 1 dotted">... </span></span><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen">1</span></font></a></span><span style="mso-bidi-font-size: 11.0pt; mso-no-proof: yes" lang="EN-US"><p></p></span></p> <p style="margin: 0cm 0cm 0pt 42pt; tab-stops: right dotted 414.8pt" class="MsoToc3"><span lang="EN-US"><a href="#_Toc260995989" target="_blank"><span style="mso-no-proof: yes"><font face="Calibri">2.1.1</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-no-proof: yes" lang="EN-US"><span lang="EN-US">记录的内容</span></span><font face="Calibri"><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen"><span style="mso-tab-count: 1 dotted">... </span></span><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen">1</span></font></a></span><span style="mso-bidi-font-size: 11.0pt; mso-no-proof: yes" lang="EN-US"><p></p></span></p> <p style="margin: 0cm 0cm 0pt 42pt; tab-stops: right dotted 414.8pt" class="MsoToc3"><span lang="EN-US"><a href="#_Toc260995990" target="_blank"><span style="mso-no-proof: yes"><font face="Calibri">2.1.2</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-no-proof: yes" lang="EN-US"><span lang="EN-US">日志记录的位置及相应的内容</span></span><font face="Calibri"><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen"><span style="mso-tab-count: 1 dotted">... </span></span><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen">2</span></font></a></span><span style="mso-bidi-font-size: 11.0pt; mso-no-proof: yes" lang="EN-US"><p></p></span></p> <p style="margin: 0cm 0cm 0pt 42pt; tab-stops: right dotted 414.8pt" class="MsoToc3"><span lang="EN-US"><a href="#_Toc260995991" target="_blank"><span style="mso-no-proof: yes"><font face="Calibri">2.1.3</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-no-proof: yes" lang="EN-US"><span lang="EN-US">日志的类型</span></span><font face="Calibri"><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen"><span style="mso-tab-count: 1 dotted">... </span></span><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen">2</span></font></a></span><span style="mso-bidi-font-size: 11.0pt; mso-no-proof: yes" lang="EN-US"><p></p></span></p> <p style="margin: 0cm 0cm 0pt 42pt; tab-stops: right dotted 414.8pt" class="MsoToc3"><span lang="EN-US"><a href="#_Toc260995992" target="_blank"><span style="mso-no-proof: yes"><font face="Calibri">2.1.4</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-no-proof: yes" lang="EN-US"><span lang="EN-US">日志功能的配置</span></span><font face="Calibri"><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen"><span style="mso-tab-count: 1 dotted">... </span></span><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen">3</span></font></a></span><span style="mso-bidi-font-size: 11.0pt; mso-no-proof: yes" lang="EN-US"><p></p></span></p> <p style="margin: 0cm 0cm 0pt 42pt; tab-stops: right dotted 414.8pt" class="MsoToc3"><span lang="EN-US"><a href="#_Toc260995993" target="_blank"><span style="mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Calibri">2.1.5</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-font-kerning: 0pt; mso-no-proof: yes" lang="EN-US"><span lang="EN-US">配置节类的用法</span></span><font face="Calibri"><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen"><span style="mso-tab-count: 1 dotted">... </span></span><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen">11</span></font></a></span><span style="mso-bidi-font-size: 11.0pt; mso-no-proof: yes" lang="EN-US"><p></p></span></p> <p style="margin: 0cm 0cm 0pt 21pt; tab-stops: right dotted 414.8pt" class="MsoToc2"><span lang="EN-US"><a href="#_Toc260995994" target="_blank"><span style="mso-no-proof: yes"><font face="Calibri">2.2</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-no-proof: yes" lang="EN-US"><span lang="EN-US">数据库日志</span></span><font face="Calibri"><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen"><span style="mso-tab-count: 1 dotted">... </span></span><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen">12</span></font></a></span><span style="mso-bidi-font-size: 11.0pt; mso-no-proof: yes" lang="EN-US"><p></p></span></p> <p style="margin: 0cm 0cm 0pt 21pt; tab-stops: right dotted 414.8pt" class="MsoToc2"><span lang="EN-US"><a href="#_Toc260995995" target="_blank"><span style="mso-no-proof: yes"><font face="Calibri">2.3</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-no-proof: yes" lang="EN-US"><span lang="EN-US">文件日志</span></span><font face="Calibri"><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen"><span style="mso-tab-count: 1 dotted">... </span></span><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen">13</span></font></a></span><span style="mso-bidi-font-size: 11.0pt; mso-no-proof: yes" lang="EN-US"><p></p></span></p> <p style="margin: 0cm 0cm 0pt 42pt; tab-stops: right dotted 414.8pt" class="MsoToc3"><span lang="EN-US"><a href="#_Toc260995996" target="_blank"><span style="mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Calibri">2.3.1</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-font-kerning: 0pt; mso-no-proof: yes" lang="EN-US"><span lang="EN-US">记录方式</span></span><font face="Calibri"><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen"><span style="mso-tab-count: 1 dotted">... </span></span><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen">13</span></font></a></span><span style="mso-bidi-font-size: 11.0pt; mso-no-proof: yes" lang="EN-US"><p></p></span></p> <p style="margin: 0cm 0cm 0pt 42pt; tab-stops: right dotted 414.8pt" class="MsoToc3"><span lang="EN-US"><a href="#_Toc260995997" target="_blank"><span style="mso-font-kerning: 0pt; mso-no-proof: yes"><font face="Calibri">2.3.2</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-font-kerning: 0pt; mso-no-proof: yes" lang="EN-US"><span lang="EN-US">文件日志的格式</span></span><font face="Calibri"><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen"><span style="mso-tab-count: 1 dotted">... </span></span><span style="display: none; color: windowtext; text-decoration: none; text-underline: none; mso-no-proof: yes; mso-hide: screen">13</span></font></a></span><span style="mso-bidi-font-size: 11.0pt; mso-no-proof: yes" lang="EN-US"><p></p></span></p> <p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><p><font face="Calibri"> </font></p></span></p></sdt>
使用.NET平台,引入微软企业库4.1中的日志模块,利用它实现文件日志的记录。
l 用户操作日志,对数据库的操作日志,包括:增加,修改,删除,查询,登录,退出。
l 系统运行异常信息,包括:数据库操作异常,文件资源操作异常,以及其他资源的操作异常。
l 前台对后台服务调用的参数传递,包括:方法的名称,方法的参数和值。
1. 数据库
记录用户操作日志,对数据库的操作;
记录系统运行的异常信息
记录用户登录、退出系统的行为
2. 文件1
记录用户操作日志,对数据库的操作;
记录系统运行的异常信息
记录用户登录、退出系统的行为
3. 文件2
前台调用后台服务的方法和传递的参数
/// <summary>
/// 日志类型
/// </summary>
[DataContract]
[Flags]
public enum LogType
{
[EnumMember]
[EnumDescription("添加成功")]
AddSuccess = 1,
[EnumMember]
[EnumDescription("修改成功")]
ModifySuccess = 2,
[EnumMember]
[EnumDescription("删除成功")]
DeleteSuccess = 4,
[EnumMember]
[EnumDescription("获取成功")]
GetSuccess = 8,
[EnumMember]
[EnumDescription("登录成功")]
LogonSuccess = 16,
[EnumMember]
[EnumDescription("退出成功")]
LogoffSuccess = 32,
[EnumMember]
[EnumDescription("添加失败")]
AddFail = 64,
[EnumMember]
[EnumDescription("修改失败")]
ModifyFail = 128,
[EnumMember]
[EnumDescription("删除失败")]
DeleteFail = 256,
[EnumMember]
[EnumDescription("获取失败")]
GetFail = 512,
[EnumMember]
[EnumDescription("登录失败")]
LogonFail = 1024,
[EnumMember]
[EnumDescription("退出失败")]
LogoffFail = 2048,
[EnumMember]
[EnumDescription("未知")]
Unknow = 4096,
[EnumMember]
[EnumDescription("事务成功")]
TransactionSuccess = 8192,
[EnumMember]
[EnumDescription("事务失败")]
TransactionFail = 16384
}
使用web.config文件进行系统日志功能的配置,包括是否记录日志,是否记录异常信息,是否某一种类型的日志等一些开关的控制。
1. Web.config文件中的系统日志配置。
<configuration>
<configSections>
<section name="logSettings" type="KB.DSN.Entity.LoggingSection, KB.DSN.Entity.Server"/>
</configSections>
<logSettings isLogging="true">
<wcfCall isLogging="true"></wcfCall>
<database isLogging="true">
<add isLogging="true">
<exception isLogging="true"></exception>
<normal isLogging="true"></normal>
</add>
<modify isLogging="true">
<exception isLogging="true"></exception>
<normal isLogging="true"></normal>
</modify>
<delete isLogging="true">
<exception isLogging="true"></exception>
<normal isLogging="true"></normal>
</delete>
<get isLogging="true">
<exception isLogging="true"></exception>
<normal isLogging="true"></normal>
</get>
<logon isLogging="true">
<exception isLogging="true"></exception>
<normal isLogging="true"></normal>
</logon>
<logoff isLogging="true">
<exception isLogging="true"></exception>
<normal isLogging="true"></normal>
</logoff>
</database>
<file isLogging="true">
<add isLogging="true">
<exception isLogging="true"></exception>
<normal isLogging="true"></normal>
</add>
<modify isLogging="true">
<exception isLogging="true"></exception>
<normal isLogging="true"></normal>
</modify>
<delete isLogging="true">
<exception isLogging="true"></exception>
<normal isLogging="true"></normal>
</delete>
<get isLogging="true">
<exception isLogging="true"></exception>
<normal isLogging="true"></normal>
</get>
<logon isLogging="true">
<exception isLogging="true"></exception>
<normal isLogging="true"></normal>
</logon>
<logoff isLogging="true">
<exception isLogging="true"></exception>
<normal isLogging="true"></normal>
</logoff>
</file>
</logSettings>
</configuration>
2. web.config文件中日志配置节对应的类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
namespace KB.DSN.Entity
{
public class LoggingSection : ConfigurationSection
{
public LoggingSection()
{ }
[ConfigurationProperty ("isLogging")]
public bool IsLogging
{
get { return (bool)this["isLogging"]; }
set{this["isLogging"]=value;}
}
[ConfigurationProperty ("database")]
public DatabaseElement Database
{
get{ return (DatabaseElement)this["database"];}
set{this["database"]=value;}
}
[ConfigurationProperty("file")]