NServicebus 添加到旧版 Windows 服务
我有一个简单的类,它为旧版 Windows 服务设置 NserviceBus。当服务启动时会调用此配置。当我将应用程序作为控制台应用程序运行时,会拾取 App.config 中的配置,但是当我将应用程序作为 Windows 服务运行时,不会拾取 App.config 配置。有什么方法可以指定应用程序配置位置吗? (正如我对 log4net.config 所做的那样)。
namespace MossSapUploadInterface
{
public static class BootStrapper
{
public static void Init()
{
var config = AppDomain.CurrentDomain.BaseDirectory + "log4net.config";
XmlConfigurator.Configure(new FileInfo(config));
var log = LogManager.GetLogger(typeof(BootStrapper));
ObjectFactory.Initialize(x => x.AddRegistry<MessageServiceRegistry>());
ObjectFactory.Configure(x => x.For<ILog>().TheDefault.Is.Object(log));
var bus = Configure.With()
.StructureMapBuilder(ObjectFactory.Container)
.MsmqTransport()
.IsTransactional(true)
.UnicastBus()
.ImpersonateSender(false)
.XmlSerializer()
.CreateBus()
.Start();
SetLoggingLibrary.Log4Net();
}
}
}
I have a simple class which sets up NserviceBus for a legacy windows service. This configuration is called when the service starts up. When I run the application as a console app the configuration in the App.config is picked up, however when running the application as a windows service the App.config configuration isn't picked up. Is there any way I can specify the app config location? (as I have done with the log4net.config).
namespace MossSapUploadInterface
{
public static class BootStrapper
{
public static void Init()
{
var config = AppDomain.CurrentDomain.BaseDirectory + "log4net.config";
XmlConfigurator.Configure(new FileInfo(config));
var log = LogManager.GetLogger(typeof(BootStrapper));
ObjectFactory.Initialize(x => x.AddRegistry<MessageServiceRegistry>());
ObjectFactory.Configure(x => x.For<ILog>().TheDefault.Is.Object(log));
var bus = Configure.With()
.StructureMapBuilder(ObjectFactory.Container)
.MsmqTransport()
.IsTransactional(true)
.UnicastBus()
.ImpersonateSender(false)
.XmlSerializer()
.CreateBus()
.Start();
SetLoggingLibrary.Log4Net();
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决此问题的一种方法是实现您自己的自定义配置源:
http ://sourceforge.net/apps/mediawiki/nservicebus/index.php?title=Overriding_Configuration
One way to solve this would be to implement your own custom config source:
http://sourceforge.net/apps/mediawiki/nservicebus/index.php?title=Overriding_Configuration
我可以确认我错了。配置是从 App.config 中获取的。通过以下日志验证:
似乎结构映射配置确实在当前域目录中查找配置,而不是我对默认服务目录的第一个想法:“c:\Windows\system32...”
I can confirm I was wrong. The configuration is picked up from the App.config. As verified by the following log:
Seems the structuremap config does look in current domain directory for the configuration, as opposed to my first thoughts of the default services directory: "c:\Windows\system32..."