-
Notifications
You must be signed in to change notification settings - Fork 26
Description
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:
- 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"
- 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();
- Add the following line to the configure method of your Startup class
loggerFactory.AddSerilog();
- 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?