gpt4 book ai didi

NServiceBus + Common.Logging + NLog

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

我想弄清楚如何将 NServiceBus 与 Common.Logging 结合使用。我只是无法让它运行。我尝试开发一个仅用于教育目的的小型演示应用程序。

我所做的是:

1) 创建一个简单的控制台应用程序并导入 Common.Logging 和 Common,Logging.NLog,添加一些 Info 消息并添加一个 App.Config 文件:

<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
<arg key="level" value="DEBUG" />
<arg key="showLogName" value="true" />
<arg key="showDataTime" value="true" />
<arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
</factoryAdapter>
</logging>
</common>
</configuration>

那工作得很好。但是当我包含 NServiceBus 时:
var bus = Configure.With().DefaultBuilder()
.XmlSerializer()
.MsmqTransport()
.IsTransactional( true )
.UnicastBus()
.MsmqSubscriptionStorage()
.CreateBus()
.Start( () => Configure.Instance.ForInstallationOn<NServiceBus.Installation.Environments.Windows>().Install() );

我得到这个异常(exception):
System.TypeInitializationException was unhandled
Message=The type initializer for 'NServiceBus.Configure' threw an exception.
Source=NServiceBus.Core
TypeName=NServiceBus.Configure
StackTrace:
at NServiceBus.Configure.With()
at ConsoleApplication1.Program.Main(String[] args) in D:\Development\katas\ConsoleApplication1\ConsoleApplication1\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: Common.Logging.ConfigurationException
Message=ConfigurationReader Common.Logging.Configuration.DefaultConfigurationReader returned unknown settings instance of type Common.Logging.Configuration.LogSetting
Source=NServiceBus.Core
StackTrace:
at Common.Logging.Configuration.ArgUtils.Guard[T](Function`1 function, String messageFormat, Object[] args)
at Common.Logging.Configuration.ArgUtils.Guard(Action action, String messageFormat, Object[] args)
at Common.Logging.LogManager.BuildLoggerFactoryAdapter()
at Common.Logging.LogManager.get_Adapter()
at Common.Logging.LogManager.GetLogger(String name)
at NServiceBus.Configure..cctor()
InnerException: System.ArgumentOutOfRangeException
Message=Type 'Common.Logging.Configuration.LogSetting, Common.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e' of parameter 'sectionResult' is not assignable to target type 'Common.Logging.Configuration.LogSetting, NServiceBus.Core, Version=3.2.0.0, Culture=neutral, PublicKeyToken=9fc386479f8a226c'
Parameter name: sectionResult
Actual value was Common.Logging.Configuration.LogSetting.
Source=NServiceBus.Core
ParamName=sectionResult
StackTrace:
at Common.Logging.Configuration.ArgUtils.AssertIsAssignable[T](String paramName, Type valType, String messageFormat, Object[] args)
at Common.Logging.Configuration.ArgUtils.AssertIsAssignable[T](String paramName, Type valType)
at Common.Logging.LogManager.<>c__DisplayClass3.<BuildLoggerFactoryAdapter>b__1()
at Common.Logging.Configuration.ArgUtils.<>c__DisplayClass13.<Guard>b__12()
at Common.Logging.Configuration.ArgUtils.Guard[T](Function`1 function, String messageFormat, Object[] args)
InnerException:

我已经尝试了 StackOverflow 和其他组中建议的几件事,但我无法让它工作。任何人都可以就如何解决这个问题提供一些建议吗?或者提供一个简单的例子?

这个设置不应该是花哨的,对吧?我现在什至不需要记录 NServiceBus 部分。

谢谢!

最佳答案

NServiceBus 有它自己的 Common.Logging 版本,它被合并并内化到 Core dll 中,它用来配置它自己的日志记录(使用 log4net)。当它启动时,它会发现 app.config 中的配置部分并尝试加载它。但是,您的配置部分(称为“日志记录”)指向外部 Common.Logging dll:

<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />

NSB 希望它看起来像:
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, NServiceBus.Core" />

因此,NSB 会引发错误。这肯定是 NSB 中的一个错误。我建议你在他们的 github 项目上创建一个问题。

虽然在您的情况下可能不是最佳解决方案,但解决它的最快方法是删除 app.config 中的日志记录部分并在代码中配置 Common.Logging。或者,完全跳过使用 Common.Logging 并直接使用 NLog。

我可能会补充说,这个问题将在 NSB 4.0 中消失,不再使用 Common.Logging。

关于NServiceBus + Common.Logging + NLog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11115376/

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