Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency Injection Using Ninject, ILoogerFactory, Serilog #39

Open
HoomanBahreini opened this issue Oct 20, 2017 · 0 comments
Open

Dependency Injection Using Ninject, ILoogerFactory, Serilog #39

HoomanBahreini opened this issue Oct 20, 2017 · 0 comments

Comments

@HoomanBahreini
Copy link

Apologies, for raising an issue... this is just a question:

I want to implement logging, using Serilog in my ASp.Net MVC Framework application. Please not that it is not a core application, so LoggerFactory is not automatically being injected into the program.

This is the tutorial explaining how everythign is done in ASP.Net MVC Core:

  1. Add Serilog Nuger Packages

"Serilog": "2.2.0",
"Serilog.Extensions.Logging": "1.2.0",
"Serilog.Sinks.RollingFile": "2.0.0",
"Serilog.Sinks.File": "3.0.0"

  1. Add the following lines to the constructor of your Startup class

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.RollingFile(Path.Combine(env.ContentRootPath, "log-{Date}.txt"))
.CreateLogger();

  1. Add the following line to the configure method of your Startup class

loggerFactory.AddSerilog();

  1. Inject the logger to your services or controllers

public class Chat : IChat
{
// Instancia del logger
ILogger logger;

    // Injectamos el logger en el constructor
    public Chat(ILogger logger)
    {
        this.logger = logger;
    }

Now this explanation is for .Net Core, I don't know how I should implement it in my MVC project...

I don't know how to Inject the LoggerFacory in my startup class... I can initialize it in my Startup and Add Serilog to it, but then how can I inject the Logger into my Constructor?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant