Giter Club home page Giter Club logo

Comments (3)

alvaromarithompson avatar alvaromarithompson commented on June 26, 2024 1

I've encountered the same problem when trying to use the Autofac serilog integration within an ASP.NET Core 2.1 application - when injecting the ILogger into a Controller, {SourceContext} is blank, but when injecting it into any other class, {SourceContext} works as expected.

2018-10-27 08:56:17.919 INF [] - This is a log line from a controller.
2018-10-27 08:56:17.927 INF [SerilogSample.Test] - This is a log line from a class.

I've put together a basic project that illustrates the problem: @alvaromarithompson/serilog-bug-sample

from autofac-serilog-integration.

nblumhardt avatar nblumhardt commented on June 26, 2024

Hi @urajkovic - thanks for the report.

I'm not sure how to approach this, I'm not up-to-date with the Autofac integration for ASP.NET Core 2, so would need some time to debug.

Help/PRs welcome, if anyone's able to take a look.

Thanks again!

from autofac-serilog-integration.

tbraz avatar tbraz commented on June 26, 2024

https://www.strathweb.com/2016/03/the-subtle-perils-of-controller-dependency-injection-in-asp-net-core-mvc/#comment-2702995712

The reason for this is something that we already explained. While controller’s constructor dependencies would be resolved by MVC from the IServiceProvider (so in our case an Autofac adapter), the instance of the controller itself (and its disposal too) is created and owned by the framework, not by the container.

The quickest workaround is to AddControllersAsServices in the configure services method

from autofac-serilog-integration.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.