Stephen Patten
Stephen Patten

Reputation: 6363

How to use ServiceStack Logging but have it delivered through the IOC container

Title about sums up what I'm looking to achieve, although now that I'm posting some code I would also like to know if the LogFactory in the correct place.

Thank you, Stephen

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)
{

}

Upvotes: 2

Views: 326

Answers (1)

mythz
mythz

Reputation: 143339

ServiceStack only supports the configuration of a single logger which should ideally be specified before the AppHost is initialized, so all static ILog initalizers for all classes in ServiceStack use the configured logger, e.g:

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

Upvotes: 1

Related Questions