gpt4 book ai didi

c#-4.0 - Log4net 在 Debug 中工作,但在 Release 构建中失败

转载 作者:行者123 更新时间:2023-12-03 22:33:59 28 4
gpt4 key购买 nike

我已经使用 log4net 一段时间了,所以我对它并不陌生。但这是我在 Windows Server 2008 R2 64 位机器上部署的第一个更大的 .NET 4.0 解决方案。

当然我先搜索了一下,发现了类似的话题。一个话题听起来完全一样——
log4net doesn't log when running a .Net 4.0 Windows application built in Release mode
- 但我的问题仍然不同。

我的部分解决方案是一个使用 log4net 的控制台应用程序。一切正常,直到我切换到发布版本。在我的电脑上测试期间,它仍然可以正常工作。但在服务器端 log4net 将不再工作。

所以我启用了 log4net 内部调试。这表明存储库冲突。我从来没有深入了解过 log4net 来完全理解它。但问题似乎在于它首先为域程序集(CRMFacade.Domain)创建了一个存储库,然后尝试为控制台应用程序创建一个存储库(CRMFacade.DataImport)。这失败了,因为默认存储库已经存在:

log4net: log4net assembly [log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821]. Loaded from [Global Assembly Cache]. (.NET Runtime [4.0.30319.225] on Microsoft Windows NT 6.1.7601 Service Pack 1)
log4net: DefaultRepositorySelector: defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository for assembly [CRMFacade.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]
log4net: DefaultRepositorySelector: Assembly [CRMFacade.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] Loaded From [C:\Program Files (x86)\CRMFacade.DataImport\CRMFacade.Domain.dll]
log4net: DefaultRepositorySelector: Assembly [CRMFacade.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified.
log4net: DefaultRepositorySelector: Assembly [CRMFacade.Domain, 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: DefaultRepositorySelector: Creating repository for assembly [CRMFacade.DataImport, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]
log4net: DefaultRepositorySelector: Assembly [CRMFacade.DataImport, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] Loaded From [C:\Program Files (x86)\CRMFacade.DataImport\CRMFacade.DataImport.exe]
log4net: DefaultRepositorySelector: Assembly [CRMFacade.DataImport, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified.
log4net: DefaultRepositorySelector: Assembly [CRMFacade.DataImport, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: repository [log4net-default-repository] already exists, using repository type [log4net.Repository.Hierarchy.Hierarchy]

有趣的是:在 Debug 构建中,控制台应用程序 (CRMFacade.DataImport) 是 log4net 为其创建存储库的第一个也是唯一一个程序集。在任何一种情况下,CRMFacade.Domain 都在 Release 版本中。 CRMFacade.Domain 还从 GAC 引用 log4net 以发出日志输出。但它没有 log4net 配置。这始终由使用域程序集的程序集提供。

很奇怪,因为它仍然可以在我的本地计算机上的 Release 版本中运行。

为了完整起见,这里是 log4net 调试输出,一切正常:
log4net: log4net assembly [log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821]. Loaded from [Global Assembly Cache]. (.NET Runtime [4.0.30319.225] on Microsoft Windows NT 6.1.7601 Service Pack 1)
log4net: DefaultRepositorySelector: defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository for assembly [CRMFacade.DataImport, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]
log4net: DefaultRepositorySelector: Assembly [CRMFacade.DataImport, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] Loaded From [C:\Program Files (x86)\CRMFacade.DataImport\CRMFacade.DataImport.exe]
log4net: DefaultRepositorySelector: Assembly [CRMFacade.DataImport, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified.
log4net: DefaultRepositorySelector: Assembly [CRMFacade.DataImport, 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 [C:\Program Files (x86)\CRMFacade.DataImport\CRMFacade.DataImport.exe.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 [ConsoleAppender] type: [log4net.Appender.ConsoleAppender]
log4net: XmlHierarchyConfigurator: Setting Property [LevelMin] to Level value [INFO]
log4net: XmlHierarchyConfigurator: Setting Collection Property [AddFilter] to object [log4net.Filter.LevelRangeFilter]
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 [%timestamp [%thread] %-5level %type: %message%newline]
log4net: PatternParser: Converter [timestamp] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [literal] Option [ [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [thread] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [literal] Option [] ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [level] Option [] Format [min=5,max=2147483647,leftAlign=True]
log4net: PatternParser: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [type] Option [] 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: XmlHierarchyConfigurator: Created Appender [ConsoleAppender]
log4net: XmlHierarchyConfigurator: Adding appender named [ConsoleAppender] to logger [root].
log4net: XmlHierarchyConfigurator: Loading Appender [RollingFileAppender] type: [log4net.Appender.RollingFileAppender]
log4net: XmlHierarchyConfigurator: Setting Property [File] to String value [C:\\Logfiles\\APPS\\Corporate\\CRMFacade\\DataImport\\log.txt]
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 [2MB]
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 [%date [%thread] %-5level %logger - %message%newline]
log4net: PatternParser: Converter [date] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [literal] Option [ [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [thread] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [literal] Option [] ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [level] Option [] Format [min=5,max=2147483647,leftAlign=True]
log4net: PatternParser: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [logger] Option [] 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 [C:\Logfiles\APPS\Corporate\CRMFacade\DataImport]
log4net: RollingFileAppender: curSizeRollBackups starts at [0]
log4net: FileAppender: Opening file for writing [C:\Logfiles\APPS\Corporate\CRMFacade\DataImport\log.txt] append [True]
log4net: XmlHierarchyConfigurator: Created Appender [RollingFileAppender]
log4net: XmlHierarchyConfigurator: Adding appender named [RollingFileAppender] to logger [root].
log4net: XmlHierarchyConfigurator: Hierarchy Threshold []

最佳答案

我们遇到了同样的问题。我仍然不清楚根本原因是什么,但我们让 log4net 再次工作。我们仅在使用网站程序集上的 XmlConfiguratorAttribute 配置 log4net 的网站中遇到问题。我们通过调用 XmlConfigurator.Configure() 设法解决了这个问题。直接来自 Application_Start()。不是一个很好的解决方案,但它似乎有效。

关于c#-4.0 - Log4net 在 Debug 中工作,但在 Release 构建中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6466245/

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