1.配置:

<configSections>节点下添加:

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />

<configuration>节点下添加:

<log4net>

    <root>

      <level value="ERROR"/>

      <appender-ref ref="LogFileAppender"/>

    </root>

    <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender,log4net">

      <param name="File" value="D:\Logs\SupervisionManageSys\"/>

      <param name="AppendToFile" value="true"/>

      <param name="MaxSizeRollBackups" value="-1"/>

      <param name="MaximumFileSize" value="5MB"/>

      <param name="RollingStyle" value="Composite"/>

      <param name="DatePattern" value="&quot;Logs_&quot;yyyyMMdd&quot;.txt&quot;"/>

      <param name="StaticLogFileName" value="false"/>

      <Encoding value="UTF-8"/>

      <layout type="log4net.Layout.PatternLayout,log4net">

        <param name="ConversionPattern" value="%d -----%-5p----- %n %m -----Thread[%t], %c, Line%L----- %n%n"/>

      </layout>

      <filter type="log4net.Filter.LevelRangeFilter">

        <param name="LevelMin" value="ALL"/>

        <param name="LevelMax" value="OFF"/>

      </filter>

    </appender>

  </log4net>

Properties:AssemblyInfo.cs下添加:

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Web.config", Watch = true)]

2.调用:

try

            {

               //将提醒实体插入提醒表,返回新插入提醒记录ID

               int? intRet=this.conn.Insert(RemindInfoItem);

                log.Info("添加提醒记录成功。");

               return intRet;

            }

           catch(Exception e)

            {

                log.Error("添加提醒记录数据失败", e);

               return -1;

            }