2013-04-04 31 views
2

標題關於總結我想要實現的,雖然現在我發佈一些代碼我也想知道如果LogFactory在正確的位置。如何使用ServiceStack日誌記錄,但通過國際奧委會容器

謝謝 斯蒂芬

public class ContactAppHost : AppHostBase 
{ 
    //Tell Service Stack the name of your application and where to find your web services 
    public ContactAppHost() : base("Contact Web Services", typeof (ContactService).Assembly) 
    { 
     // Built into the framework without the IOC 
     LogManager.LogFactory = new NLogFactory(); 
    } 

    public override void Configure(Funq.Container container) 
    { 
     //register any dependencies your services use, e.g: 
     container.Register<ICacheClient>(new MemoryCacheClient()); 
    } 
} 


protected void Application_Start(object sender, EventArgs e) 
{ 
    new ContactAppHost().Init(); 
} 

protected void Application_Error(object sender, EventArgs e) 
{ 

} 

回答

1

ServiceStack只支持理想情況下應該在APPHOST之前指定一個記錄器的配置被初始化,所以所有的靜態ILog initalizers在ServiceStack所有類使用的配置記錄儀,例如:

protected void Application_Start(object sender, EventArgs e) 
{ 
    LogManager.LogFactory = new NLogFactory(); 
    new ContactAppHost().Init(); 
} 
+0

好的,在哪裏可以完成記錄器的初始化,但是IOC容器如何將它傳送到其他位置的ILog屬性呢? – 2013-04-04 20:05:24

+0

@StephenPatten我們只使用靜態初始化器,所以我們絕不會將它注入到IOC中。 – mythz 2013-04-04 20:32:58

+0

好的,想從男人那裏聽到..謝謝德米斯! – 2013-04-04 20:47:57