TraceListener in OWIN Self Hosting

前端 未结 3 810
谎友^
谎友^ 2020-12-05 23:51

I am using Microsoft.Owin.Hosting to host the following, very simple web app.

Here is the call to start it:



        
3条回答
  •  醉酒成梦
    2020-12-06 00:35

    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(dummyFactory));
    
    using (WebApp.Start(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;
        }
    }
    

提交回复
热议问题