'Microsoft Logger with serilog
I was wondering if it was possible in a console Application .Net Framework, the latest version, to be able to associate Serilog with Microsoft logger at the start and in the various classes invoke Microsoft logger without bringing me dependencies. On the internet, I have seen many implementations but every time they call a class other than where the logger was declared, it is passed as a function parameter and without "using Serilog" inside my class
For Example in my Main method i set Microsoft.Logging with serilog and in my class i call Microsoft Logging and save into ILogger variable
public float operation (string operation, float a, float b)
{
ILogger<calculator> log = Microsoft.Extensions.Logging.GetLogging(); //This method not exixst is only for example
switch(operation)
{
case "Add":
log.LogInformation("Add");
break;
case "Sub":
log.LogInformation("Sub");
break;
case "Div":
log.LogInformation("Div");
break;
case "Mult":
log.LogInformation("Mult");
break;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
