我正在尝试配置使用(LocalDb)\ v11.0来存储日志消息的log4net AdoNetAppender
但是以下错误阻止了它的工作。是缺少的东西还是localdb的其他配置?该应用程序是Asp.net MVC。谢谢
错误:
log4net:ERROR [AdoNetAppender] ErrorCode: GenericFailure. Could not open database connection []. Connection string context [Unable to resolve connection string from ConnectionString, ConnectionStrings, or AppSettings.].
配置:
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="100" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="Data Source=(LocalDb)\v11.0;Initial Catalog=DataTablesWebApp;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />...
当我启用log4net调试时,我会在应用启动时获得以下输出。它显示了adonetappender正在成功创建。
log4net: log4net assembly [log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a]. Loaded from [C:\Users\Tim\AppData\Local\Temp\Temporary ASP.NET Files\root\acd83218\3d92d868\assembly\dl3\e3a91527\cd04f7e4_da6acf01\log4net.dll]. (.NET Runtime [4.0.30319.34011] on Microsoft Windows NT 6.2.9200.0)
log4net: defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy]
log4net: Creating repository for assembly [DataTablesWebApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]
log4net: Assembly [DataTablesWebApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] Loaded From [C:\Users\Tim\AppData\Local\Temp\Temporary ASP.NET Files\root\acd83218\3d92d868\assembly\dl3\671cfc13\aa27e409_006bcf01\DataTablesWebApp.dll]
log4net: Assembly [DataTablesWebApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified.
log4net: Assembly [DataTablesWebApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: Creating repository [log4net-default-repository] using type [log4net.Repository.Hierarchy.Hierarchy]
log4net: configuring repository [log4net-default-repository] using .config file section
log4net: Application config file is [c:\users\tim\documents\visual studio 2013\Projects\DataTablesWebApp\DataTablesWebApp\web.config]
log4net: Configuring Repository [log4net-default-repository]
log4net: Configuration update mode [Merge].
log4net: Logger [root] Level string is [ALL].
log4net: Logger [root] level set to [name="ALL",value=-2147483648].
log4net: Loading Appender [AdoNetAppender] type: [log4net.Appender.AdoNetAppender]
log4net: Setting Property [BufferSize] to Int32 value [100]
log4net: Setting Property [ConnectionType] to String value [System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]
log4net: Setting Property [ConnectionString] to String value [Data Source=(LocalDb)\v11.0;Initial Catalog=DataTablesWebApp;Integrated Security=SSPI;]
log4net: Setting Property [CommandText] to String value [INSERT INTO Log4Net ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)]
log4net: Setting Property [ParameterName] to String value [@log_date]
log4net: Setting Property [DbType] to DbType value [DateTime]
log4net: Setting Property [Layout] to object [log4net.Layout.RawTimeStampLayout]
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter]
log4net: Setting Property [ParameterName] to String value [@thread]
log4net: Setting Property [DbType] to DbType value [String]
log4net: Setting Property [Size] to Int32 value [255]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [ConversionPattern] to String value [%thread]
log4net: Converter [thread] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter]
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter]
log4net: Setting Property [ParameterName] to String value [@log_level]
log4net: Setting Property [DbType] to DbType value [String]
log4net: Setting Property [Size] to Int32 value [50]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [ConversionPattern] to String value [%level]
log4net: Converter [level] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter]
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter]
log4net: Setting Property [ParameterName] to String value [@logger]
log4net: Setting Property [DbType] to DbType value [String]
log4net: Setting Property [Size] to Int32 value [255]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [ConversionPattern] to String value [%logger]
log4net: Converter [logger] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter]
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter]
log4net: Setting Property [ParameterName] to String value [@message]
log4net: Setting Property [DbType] to DbType value [String]
log4net: Setting Property [Size] to Int32 value [4000]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [ConversionPattern] to String value [%message]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter]
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter]
log4net: Setting Property [ParameterName] to String value [@exception]
log4net: Setting Property [DbType] to DbType value [String]
log4net: Setting Property [Size] to Int32 value [2000]
log4net: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter]
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter]
log4net: Created Appender [AdoNetAppender]
log4net: Adding appender named [AdoNetAppender] to logger [root].
log4net: Loading Appender [Console] type: [log4net.Appender.ConsoleAppender]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [ConversionPattern] to String value [%date %-5level: %message%newline]
log4net: Converter [date] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [level] Option [] Format [min=5,max=2147483647,leftAlign=True]
log4net: Converter [literal] Option [: ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [Layout] to object [log4net.Layout.PatternLayout]
log4net: Created Appender [Console]
log4net: Adding appender named [Console] to logger [root].
log4net: Loading Appender [RollingFileAppender] type: [log4net.Appender.RollingFileAppender]
log4net: Setting Property [File] to String value [Log4Net.txt]
log4net: Setting Property [AppendToFile] to Boolean value [True]
log4net: Setting Property [RollingStyle] to RollingMode value [Size]
log4net: Setting Property [MaxSizeRollBackups] to Int32 value [10]
log4net: Setting Property [MaximumFileSize] to String value [50MB]
log4net: Setting Property [StaticLogFileName] to Boolean value [True]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [ConversionPattern] to String value [%date %-5level[%logger]: %message%newline]
log4net: Converter [date] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [level] Option [] Format [min=5,max=2147483647,leftAlign=True]
log4net: Converter [literal] Option [[] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [logger] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option []: ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [Layout] to object [log4net.Layout.PatternLayout]
log4net: Searched for existing files in [c:\users\tim\documents\visual studio 2013\Projects\DataTablesWebApp\DataTablesWebApp]
log4net: curSizeRollBackups starts at [0]
log4net: Opening file for writing [c:\users\tim\documents\visual studio 2013\Projects\DataTablesWebApp\DataTablesWebApp\Log4Net.txt] append [True]
log4net: Created Appender [RollingFileAppender]
log4net: Adding appender named [RollingFileAppender] to logger [root].
log4net: Hierarchy Threshold []
答案 0 :(得分:0)
你应该替换:
<connectionString connectionString=...
由:
<connectionString value=...
See the log4net documentation for an example
如果您使用的是Log4Net 1.2.11或更高版本,则可以用<connectionString>
元素替换<connectionStringName>
元素,并将连接字符串保留在标准<connectionStrings>
中配置部分。
答案 1 :(得分:0)
如果要使用现有的连接字符串名称,请使用 connectionStringName 。使用 connectionStrings 定义连接字符串的完整路径
示例应用程序连接字符串:
<connectionStrings>
<add name="myDB"
connectionString="Data Source=(localdb)\mssqllocaldb;Initial Catalog=dbName;Integrated Security=True;MultipleActiveResultSets=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
您将使用:
<connectionStringName value="Data Source=(localdb)\mssqllocaldb;Initial Catalog=dbName;Integrated Security=True;MultipleActiveResultSets=True" />
或
<connectionStrings value="myDB" />