log4net创建系统日志的详细步骤(2)


         <appender type="log4net.Appender.ADONetAppender">
             <!--存储到数据库的操作-->
             <bufferSize value="10"/>
             <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
             <connectionString value="server=.;database=Log4Net;user id=sa;password=saa"/>
             <commandText value="INSERT INTO _Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date,                                @log_thread, @log_level, @log_logger, @log_message, @log_exception)"/>
             <parameter>
                 <parameterName value="@log_date"/>
                 <dbType value="DateTime"/>
                 <layout type="log4net.Layout.RawTimeStampLayout"/><!--可以认为是记录日志的时间-->
             </parameter>
             <parameter>
                 <parameterName value="@log_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="@log_logger"/>
                 <dbType value="String"/>
                 <size value="255"/>
                 <layout type="log4net.Layout.PatternLayout">
                     <conversionPattern value="%logger"/><!--哪个记录器存储的该日志-->
                 </layout>
             </parameter>
             <parameter>
                 <parameterName value="@log_message"/>
                 <dbType value="String"/>
                 <size value="4000"/>
                 <layout type="log4net.Layout.PatternLayout">
                     <conversionPattern value="%message"/><!--日志信息-->
                 </layout>
             </parameter>
             <parameter>
                 <parameterName value="@log_exception"/>
                 <dbType value="String"/>
                 <size value="255"/>
                 <layout type="log4net.Layout.ExceptionLayout"/><!--异常信息-->
             </parameter> 
         </appender>

另外一种写入文件的方式配置

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjgwws.html