serilog-web / classic-webapi

ASP.NET WebAPI support for SerilogWeb.Classic

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't work with OWIN

rosrosros opened this issue · comments

Using this package works fine with normal webapi. But in a project where Global.asax is replaved with Startup.cs exceptions are not being caught.

This has no effect in owin
GlobalConfiguration.Configuration.Services.Add(typeof(IExceptionLogger), new MyLogger());

Where this on the other hand works:

HttpConfiguration config = new HttpConfiguration();
config.Services.Add(typeof(IExceptionLogger), new MyLogger());

I would love to do a PR but don't know how you would solve this issue

Regards

Thanks for the note. I think this is expected, though I don't have a great solution to propose.

Have you looked at: https://github.com/serilog-web/owin ?

Though we ended up agreeing that it should be discontinued (see the single issue in that repo) I'd be interested in any thoughts you have on how to go about this better.

We would love to see this package working with OWIN. Please could we can re-open this issue?

As @rosrosros points out, manually adding the relevant pieces to the HttpConfiguration is what is required for OWIN based projects.

If we reverted StoreWebApInfoInHttpContextActionFilter.cs to a public class and update the README.md with instructions for OWIN to add the following:

HttpConfiguration config = new HttpConfiguration();
config.Services.Add(typeof(IExceptionLogger), new WebApiExceptionLogger());
config.Filters.Add(new StoreWebApInfoInHttpContextActionFilter());

Would this be sufficient?

Many thanks

Actually, this package has a dependency on SerilogWeb.Classic and on System.Web... most of the code here would not work in self-hosted OWIN (requires HttpContext.Current, registers a HttpModule etc).

It would still kind of feel like a hack, wouldn't it ?

I see, yes; it only gets it working for OWIN hosted by IIS (which is what we have in production currently). Perhaps it needs separate packages altogether then (SerilogWeb.Owin, SerilogWeb.Owin.WebApi). Although, I noticed SerilogWeb.Owin is deprecated. Further thought required I think!