How to enable OWIN logging in Windows 7

I am trying to implement login to my own OWIN hosting solution.

My MiddleWareclass is as follows:

public class HostingMiddleware : OwinMiddleware
{
    private readonly ILogger _logger;

    public HostingMiddleware(OwinMiddleware next, IAppBuilder builder)
        : base(next)
    {
        _logger = builder.CreateLogger<HostingMiddleware>();
    }

    public override Task Invoke(IOwinContext context)
    {
        _logger.WriteVerbose(string.Format("{0} {1}: {2}"));
        context.Response.Headers.Add("Content-Type", new[] 
                                                     { 
                                                        "text/plain"
                                                     });
        return Invoke(context);
    }
}

Then I use this in my class Startup.

public class Startup
{
   public void Configuration(IAppBuilder builder)
   {
      // Initialize the configuration for Web API self-host.
      HttpConfiguration config = new HttpConfiguration();

      // Map the default Web API HTTP Route
      config.Routes.MapHttpRoute(
          name: "DefaultApi",
          routeTemplate: "api/{controller}/{id}",
          defaults: new { id = RouteParameter.Optional }
      );

      // Use Web API
      builder.UseWebApi(config);

      builder.Use<HostingMiddleware>(builder);
   }
}

When I delete builder.Use<HostingMiddleware>(builder);, I can make an HTTP request and get a response, however, when I implement my class MiddleWare, I get:

No WebSocket support detected, Windows 8 or later is required.

Going forward, the magazine does not work as it should. Of course, there is a way to make the log work in Windows 7, otherwise the functionality will be useless? Any ideas on what I need to do?

Thanks in advance.

+4
source share
1 answer

Next.Invoke(context), , .

"" - , , .

oWin - .


public class HostingMiddleware : OwinMiddleware
{
    private readonly ILogger _logger;

    public HostingMiddleware(OwinMiddleware next, IAppBuilder builder)
        : base(next)
    {
        _logger = builder.CreateLogger();
    }

    public async override Task Invoke(IOwinContext context)
    {
        _logger.WriteVerbose(string.Format("{0} --- {1}", context.Request.Uri.AbsolutePath, context.Request.QueryString);
        await Next.Invoke(context);
    }
}

: OWIN, Katana

+5

All Articles