2016-05-06 24 views
0

我做了很多關於如何在masstransit中記錄數據的研究(在官方文檔,github的問題頁面和stackoverflow)(記住日誌功能從任何日誌實現中分離),甚至在masstransit的github着名示例中作爲Sample-ShoppingWeb採樣訂房星巴克我無法理解如何登錄應用程序數據...如何登錄masstransit?

我安裝MassTransit.NLog和波紋管配置我的車:

var bus = BusConfigurator.ConfigureBus((cfg, host) => 
{ 
    ... 
    cfg.ReceiveEndpoint(host, RabbitMqConstants.SagaQueue, e => 
    { 
     cfg.UseNLog(); 
... 

...並給予一看NLOG教程https://github.com/NLog/NLog/wiki/Tutorial我安裝的軟件包NLog.Config(即具有的NuGet依賴NLOGNLog.Schema) 和我的項目中添加文件NLOG的.config和** NLog.xsd * ... ... 的 問題不在NLOG本身,而是我不能瞭解如何登錄masstransit信息...

在我OrderStateMachine類我做以下

... 
Initially(
When(RegisterOrder) 
    .Then(context => 
    { 
     var log = Logger.Get("logfile"); 
     log.Info(context); 
     log.InfoFormat("Register Order {0}", "register"); 
     throw new ArgumentException("Test for monitoring sagas"); 
     log.Error(context); 
     //throw new ArgumentException("Test for monitoring sagas"); 
... 

我不知道即使是類和方法,我應該使用(上masstransit)...

回答

1

我明白,只是作爲參數傳遞一個NLOG工廠實例如下:cfg.UseNLog(new LogFactory());與此Logger.Get("logfile");返回Masstransit的抽象類(這種方法應該根據所需的日誌級別調用)...

偉大的抽象,太簡單了,太酷了!