Log4Net配置文件
2007-01-29 12:57 澜心 阅读(1059) 评论(0) 编辑 收藏 举报<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
</configSections>
<appSettings>
<!--数据库连接字符串 eaerserver sa thssl COA-->
<add key="ConnectionString" value="(local);UID=sa;PWD=sa;DataBase=Projet;Max Pool Size=1000"/>
</appSettings>
<system.web>
<httpRuntime maxRequestLength="102400" useFullyQualifiedRedirectUrl="true" executionTimeout="36000" />
<compilation defaultLanguage="c#" debug="true" />
<customErrors defaultRedirect="default.aspx" mode="RemoteOnly" />
<authentication mode="Windows" />
<authorization>
<allow users="*" />
</authorization>
<pages validateRequest="false"></pages>
<trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false" timeout="1440" />
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
<log4net>
<appender name="ADONetAppender_SqlServer" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="Server=192.168.0.22;UID=sa;PWD=sa;DataBase=ProjectMgr;Max Pool Size=1000"/>
<commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message]) VALUES (@log_date, @thread, @log_level, @logger, @message)" />
<parameter>
<parameterName value="@log_date" />
<dbType value="DateTime" />
<!--
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{yyyy'-'MM'-'dd HH':'mm':'ss'.'fff}" />
</layout>
-->
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
<parameter>
<parameterName value="@thread" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%thread" />
</layout>
</parameter>
<parameter>
<parameterName value="@log_level" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level" />
</layout>
</parameter>
<parameter>
<parameterName value="@logger" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%logger" />
</layout>
</parameter>
<parameter>
<parameterName value="@message" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
</layout>
</parameter>
</appender>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="log\rolling-log.txt" />
<appendToFile value="true" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="100" />
<rollingStyle value="Size" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<header value="[Header] " />
<footer value="[Footer] " />
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default level -->
<root>
<level value="INFO" />
<appender-ref ref="ADONetAppender_SqlServer" />
<appender-ref ref="RollingLogFileAppender" />
</root>
<!-- Specify the level for some specific categories -->
<logger name="ConsoleApp.LoggingExample">
<!-- <appender-ref ref="B" /> -->
<level value="ALL" />
<appender-ref ref="ADONetAppender_SqlServer" />
<appender-ref ref="RollingLogFileAppender" />
</logger>
</log4net>
</configuration>
<configuration>
<configSections>
<section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
</configSections>
<appSettings>
<!--数据库连接字符串 eaerserver sa thssl COA-->
<add key="ConnectionString" value="(local);UID=sa;PWD=sa;DataBase=Projet;Max Pool Size=1000"/>
</appSettings>
<system.web>
<httpRuntime maxRequestLength="102400" useFullyQualifiedRedirectUrl="true" executionTimeout="36000" />
<compilation defaultLanguage="c#" debug="true" />
<customErrors defaultRedirect="default.aspx" mode="RemoteOnly" />
<authentication mode="Windows" />
<authorization>
<allow users="*" />
</authorization>
<pages validateRequest="false"></pages>
<trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false" timeout="1440" />
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
<log4net>
<appender name="ADONetAppender_SqlServer" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="Server=192.168.0.22;UID=sa;PWD=sa;DataBase=ProjectMgr;Max Pool Size=1000"/>
<commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message]) VALUES (@log_date, @thread, @log_level, @logger, @message)" />
<parameter>
<parameterName value="@log_date" />
<dbType value="DateTime" />
<!--
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{yyyy'-'MM'-'dd HH':'mm':'ss'.'fff}" />
</layout>
-->
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
<parameter>
<parameterName value="@thread" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%thread" />
</layout>
</parameter>
<parameter>
<parameterName value="@log_level" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level" />
</layout>
</parameter>
<parameter>
<parameterName value="@logger" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%logger" />
</layout>
</parameter>
<parameter>
<parameterName value="@message" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
</layout>
</parameter>
</appender>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="log\rolling-log.txt" />
<appendToFile value="true" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="100" />
<rollingStyle value="Size" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<header value="[Header] " />
<footer value="[Footer] " />
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default level -->
<root>
<level value="INFO" />
<appender-ref ref="ADONetAppender_SqlServer" />
<appender-ref ref="RollingLogFileAppender" />
</root>
<!-- Specify the level for some specific categories -->
<logger name="ConsoleApp.LoggingExample">
<!-- <appender-ref ref="B" /> -->
<level value="ALL" />
<appender-ref ref="ADONetAppender_SqlServer" />
<appender-ref ref="RollingLogFileAppender" />
</logger>
</log4net>
</configuration>
Global中加入一句话
[assembly: log4net.Config.XmlConfigurator(Watch=true)]
页面这样就可以调用了
protected static readonly log4net.ILog log = log4net.LogManager.GetLogger("登陆页面");
log.Info("系统发生错误了!");