各位大神求教:为什么我的log4net可以写日志到文件但是无法写日志到数据库?配置都是从log4net手册里找的,下面是配置文件。我写的WebApi项目
1 <?xml version="1.0"?> 2 <configuration> 3 <configSections> 4 <section name="log4net" type="System.Configuration.IgnoreSectionHandler"/> 5 </configSections> 6 7 <log4net> 8 <root> 9 <level value="ALL"/> 10 <appender-ref ref="ADONetAppender"/> 11 <appender-ref ref="FileAppender"/> 12 <!--<appender-ref ref="ADONetAppender" /> 13 <appender-ref ref="SmtpAppender"/> 14 <appender-ref ref="LogFileAppender"/> 15 <appender-ref ref="ColoredConsoleAppender"/> 16 <appender-ref ref="EventLogAppender"/> 17 <append-ref ref="NetSendAppender"/> 18 <appender-ref ref="RollingFile"/>--> 19 </root> 20 21 <appender name="FileAppender" type="log4net.Appender.FileAppender"> 22 23 <!--存储到文件的操作--> 24 25 <param name="File" value="D:\mylogfile.txt"/> 26 <param name="AppendToFile" value="true"/> 27 <layout type="log4net.Layout.PatternLayout"> 28 <param name="ConversionPattern" value="%d ---- %m------%p%n"/> 29 </layout> 30 </appender> 31 32 <appender name="ADONetAppender" type="log4net.Appender.ADONetAppender"> 33 <!--存储到数据库的操作--> 34 35 <bufferSize value="1"/> 36 <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> 37 <connectionString value="Data Source=(local);Initial catalog=dev;Integrated Security=False;persist security info=True;User ID=sa;Password=1"/> 38 <commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @log_exception)"/> 39 <parameter> 40 <parameterName value="@log_date"/> 41 <dbType value="DateTime"/> 42 <layout type="log4net.Layout.PatternLayout" value="%date{yyyy'-'MM'-'dd HH':'mm':'ss'.'fff}"/> 43 </parameter> 44 <parameter> 45 <parameterName value="@thread"/> 46 <dbType value="String"/> 47 <size value="255"/> 48 <layout type="log4net.Layout.PatternLayout" value="%thread"/> 49 </parameter> 50 <parameter> 51 <parameterName value="@log_level"/> 52 <dbType value="String"/> 53 <size value="50"/> 54 <layout type="log4net.Layout.PatternLayout" value="%level"/> 55 </parameter> 56 <parameter> 57 <parameterName value="@logger"/> 58 <dbType value="String"/> 59 <size value="255"/> 60 <layout type="log4net.Layout.PatternLayout" value="%logger"/> 61 </parameter> 62 <parameter> 63 <parameterName value="@message"/> 64 <dbType value="String"/> 65 <size value="4000"/> 66 <layout type="log4net.Layout.PatternLayout" value="%message"/> 67 </parameter> 68 69 <parameter> 70 <!--异常信息--> 71 <parameterName value="@log_exception"/> 72 <dbType value="String"/> 73 <size value="255"/> 74 <layout type="log4net.Layout.ExceptionLayout"/> 75 </parameter> 76 </appender> 77 </log4net> 78 79 </configuration>
直接把日志往数据库里面存啊...你不怕日志量大,撑爆数据库啊....
有没有生成数据表呢?
有的,数据库中有Log表