gpt4 book ai didi

log4net - log4net 中的 AdoNetAppender 不记录或抛出异常

转载 作者:行者123 更新时间:2023-12-02 12:05:42 32 4
gpt4 key购买 nike

我在 log4net.config 文件中定义了一个记录器,该文件应该使用 AdoNetAppender 记录到 SQL Server 2005 的实例。在我的代码中调用该记录器,但没有记录任何消息,也没有异常被抛出。

这是我的配置文件中定义记录器和附加程序的部分:

<logger name="Log4NetSummarySqlLogger">
<level value="INFO"/>
<appender-ref ref="SummarySqlAppender"/>
</logger>

<appender name="SummarySqlAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="100" />
<!--<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />-->
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="data source=[removed];initial catalog=[removed];integrated security=false;persist security info=True;User ID=[removed];Password=[removed]" />
<commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />
<parameter>
<parameterName value="@log_date" />
<dbType value="DateTime" />
<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>
<parameter>
<parameterName value="@exception" />
<dbType value="String" />
<size value="2000" />
<layout type="log4net.Layout.ExceptionLayout" />
</parameter>

我还启用了 log4net 的内部调试,但也没有多大帮助:

log4net: log4net assembly [log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821]. Loaded from [<executable directory>\log4net.dll]. (.NET Runtime [4.0.30319.237] on Microsoft Windows NT 5.1.2600 Service Pack 3)
log4net: DefaultRepositorySelector: defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository for assembly [WindowsService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]
log4net: DefaultRepositorySelector: Assembly [WindowsService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] Loaded From [<executable directory>\WindowsService.exe]
log4net: DefaultRepositorySelector: Assembly [WindowsService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified.
log4net: DefaultRepositorySelector: Assembly [WindowsService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository [log4net-default-repository] using type [log4net.Repository.Hierarchy.Hierarchy]
log4net: XmlConfigurator: configuring repository [log4net-default-repository] using file [<executable directory>\log4net.config]
log4net: XmlConfigurator: configuring repository [log4net-default-repository] using stream
log4net: XmlConfigurator: loading XML configuration
log4net: XmlConfigurator: Configuring Repository [log4net-default-repository]
log4net: XmlHierarchyConfigurator: Configuration update mode [Merge].
log4net: XmlHierarchyConfigurator: Logger [root] Level string is [INFO].
log4net: XmlHierarchyConfigurator: Logger [root] level set to [name="INFO",value=40000].
log4net: XmlHierarchyConfigurator: Loading Appender [FileAppender] type: [log4net.Appender.RollingFileAppender]
log4net: XmlHierarchyConfigurator: Setting Property [File] to String value [<log directory>/info.log]
log4net: XmlHierarchyConfigurator: Setting Property [AppendToFile] to Boolean value [True]
log4net: XmlHierarchyConfigurator: Setting Property [RollingStyle] to RollingMode value [Size]
log4net: XmlHierarchyConfigurator: Setting Property [MaxSizeRollBackups] to Int32 value [10]
log4net: XmlHierarchyConfigurator: Setting Property [MaximumFileSize] to String value [100KB]
log4net: XmlHierarchyConfigurator: Setting Property [StaticLogFileName] to Boolean value [True]
log4net: PatternParser: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property [ConversionPattern] to String value [{%level}%date{MM/dd HH:mm:ss} - %message%newline]
log4net: PatternParser: Converter [literal] Option [{] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [level] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [literal] Option [}] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [date] Option [MM/dd HH:mm:ss] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [literal] Option [ - ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property [Layout] to object [log4net.Layout.PatternLayout]
log4net: RollingFileAppender: Searched for existing files in [<log directory>]
log4net: RollingFileAppender: curSizeRollBackups starts at [0]
log4net: FileAppender: Opening file for writing [<log directory>\info.log] append [True]
log4net: XmlHierarchyConfigurator: Created Appender [FileAppender]
log4net: XmlHierarchyConfigurator: Adding appender named [FileAppender] to logger [root].
log4net: XmlHierarchyConfigurator: Retrieving an instance of log4net.Repository.Logger for logger [Log4NetSummarySqlLogger].
log4net: XmlHierarchyConfigurator: Setting [Log4NetSummarySqlLogger] additivity to [True].
log4net: XmlHierarchyConfigurator: Logger [Log4NetSummarySqlLogger] Level string is [INFO].
log4net: XmlHierarchyConfigurator: Logger [Log4NetSummarySqlLogger] level set to [name="INFO",value=40000].
log4net: XmlHierarchyConfigurator: Loading Appender [SummarySqlAppender] type: [log4net.Appender.AdoNetAppender]
log4net: XmlHierarchyConfigurator: Setting Property [BufferSize] to Int32 value [100]
log4net: XmlHierarchyConfigurator: Setting Property [ConnectionType] to String value [System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]
log4net: XmlHierarchyConfigurator: Setting Property [ConnectionString] to String value [data source=<server>;initial catalog=<database>;integrated security=false;persist security info=True;User ID=<user>;Password=<password>]
log4net: XmlHierarchyConfigurator: Setting Property [CommandText] to String value [INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)]
log4net: XmlHierarchyConfigurator: Setting Property [ParameterName] to String value [@log_date]
log4net: XmlHierarchyConfigurator: Setting Property [DbType] to DbType value [DateTime]
log4net: XmlHierarchyConfigurator: Setting Property [Layout] to object [log4net.Layout.RawTimeStampLayout]
log4net: XmlHierarchyConfigurator: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter]
log4net: XmlHierarchyConfigurator: Setting Property [ParameterName] to String value [@thread]
log4net: XmlHierarchyConfigurator: Setting Property [DbType] to DbType value [String]
log4net: XmlHierarchyConfigurator: Setting Property [Size] to Int32 value [255]
log4net: PatternParser: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property [ConversionPattern] to String value [%thread]
log4net: PatternParser: Converter [thread] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter]
log4net: XmlHierarchyConfigurator: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter]
log4net: XmlHierarchyConfigurator: Setting Property [ParameterName] to String value [@log_level]
log4net: XmlHierarchyConfigurator: Setting Property [DbType] to DbType value [String]
log4net: XmlHierarchyConfigurator: Setting Property [Size] to Int32 value [50]
log4net: PatternParser: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property [ConversionPattern] to String value [%level]
log4net: PatternParser: Converter [level] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter]
log4net: XmlHierarchyConfigurator: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter]
log4net: XmlHierarchyConfigurator: Setting Property [ParameterName] to String value [@logger]
log4net: XmlHierarchyConfigurator: Setting Property [DbType] to DbType value [String]
log4net: XmlHierarchyConfigurator: Setting Property [Size] to Int32 value [255]
log4net: PatternParser: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property [ConversionPattern] to String value [%logger]
log4net: PatternParser: Converter [logger] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter]
log4net: XmlHierarchyConfigurator: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter]
log4net: XmlHierarchyConfigurator: Setting Property [ParameterName] to String value [@message]
log4net: XmlHierarchyConfigurator: Setting Property [DbType] to DbType value [String]
log4net: XmlHierarchyConfigurator: Setting Property [Size] to Int32 value [4000]
log4net: PatternParser: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property [ConversionPattern] to String value [%message]
log4net: PatternParser: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter]
log4net: XmlHierarchyConfigurator: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter]
log4net: XmlHierarchyConfigurator: Setting Property [ParameterName] to String value [@exception]
log4net: XmlHierarchyConfigurator: Setting Property [DbType] to DbType value [String]
log4net: XmlHierarchyConfigurator: Setting Property [Size] to Int32 value [2000]
log4net: XmlHierarchyConfigurator: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter]
log4net: XmlHierarchyConfigurator: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter]
'QTAgent32.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Transactions\v4.0_4.0.0.0__b77a5c561934e089\System.Transactions.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'QTAgent32.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'QTAgent32.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.Wrapper.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
log4net: XmlHierarchyConfigurator: Created Appender [SummarySqlAppender]
log4net: XmlHierarchyConfigurator: Adding appender named [SummarySqlAppender] to logger [Log4NetSummarySqlLogger].
log4net: XmlHierarchyConfigurator: Retrieving an instance of log4net.Repository.Logger for logger [Log4NetEventLogger].
log4net: XmlHierarchyConfigurator: Setting [Log4NetEventLogger] additivity to [True].
log4net: XmlHierarchyConfigurator: Logger [Log4NetEventLogger] Level string is [INFO].
log4net: XmlHierarchyConfigurator: Logger [Log4NetEventLogger] level set to [name="INFO",value=40000].
log4net: XmlHierarchyConfigurator: Loading Appender [EventLogAppender] type: [log4net.Appender.EventLogAppender]
log4net: XmlHierarchyConfigurator: Setting Property [LogName] to String value [Application]
log4net: XmlHierarchyConfigurator: Setting Property [ApplicationName] to String value [ConcurFilesService]
log4net: PatternParser: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property [ConversionPattern] to String value [{%level}%date{MM/dd HH:mm:ss} - %message%newline]
log4net: PatternParser: Converter [literal] Option [{] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [level] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [literal] Option [}] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [date] Option [MM/dd HH:mm:ss] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [literal] Option [ - ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property [Layout] to object [log4net.Layout.PatternLayout]
log4net: EventLogAppender: Source [ConcurFilesService] is registered to log []
log4net: XmlHierarchyConfigurator: Created Appender [EventLogAppender]
log4net: XmlHierarchyConfigurator: Adding appender named [EventLogAppender] to logger [Log4NetEventLogger].
log4net: XmlHierarchyConfigurator: Hierarchy Threshold []

FWIW,我还在其他地方定义了一个 FileAppender 并且它工作正常。

最佳答案

尝试将缓冲区大小设置为 1。您的应用程序可能会在缓冲区刷新之前退出,因此您看不到任何日志消息。

bufferSize value="1"

另一个可能的问题可能是记录器的名称。你真的有一个使用这个名字的记录器吗?尝试配置根记录器

<root>
<level value="INFO"/>
<appender-ref ref="SummarySqlAppender"/>
</root>

关于log4net - log4net 中的 AdoNetAppender 不记录或抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7109664/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com