TraceListener in OWIN Self Hosting

c#, owin

Solution

I found a solution myself. After studying the Katana source code it seems like you need to register your own `ITraceOutputFactory` instance to overrule the default trace listener (which is writing to the console).

Here is the new start call:

var dummyFactory = new DummyFactory();
var provider = ServicesFactory.Create(
    defaultServiceProvider => defaultServiceProvider.AddInstance<ITraceOutputFactory>(dummyFactory));

using (WebApp.Start<Startup>(provider, new StartOptions("http://localhost:8090")))
{
    Console.ReadLine();
}

And here is a dummy trace factory (maybe not the best solution but you can replace it with something serving your purpose a little better):

public class DummyFactory : ITraceOutputFactory
{
    public TextWriter Create(string outputFile)
    {
        return TextWriter.Null;
    }
}

Problem

I am using `Microsoft.Owin.Hosting` to host the following, very simple web app. Here is the call to start it: ``` WebApp.Start<PushServerStartup>("http://localhost:8080/events"); ``` Here is the startup class I am using: ``` public class PushServerStartup { public void Configuration(IAppBuilder app) { app.MapHubs(); } } ``` I am running this inside a console application that does a lot of other things including routing trace writing to certain files etc. But all of a sudden (when activating the OWIN hosting) I am seeing trace messages written to the console that are normally routed somewhere else. Obviously there are some trace listeners active in the OWIN hosting framework. How can I switch them off?

Original source