I can not find any resources for installing Serilog in an ASP.Net 4.7.1 WebApi project. Can someone help me out? There are a ton of .Net Core resources but that does not help.
We recommend supported versions of each platform. For example, the current minimum version of . NET Framework supported by Microsoft is 4.6. 2, though we would recommend 4.8 or newer.
Serilog is a logging library for . NET and C# that allows for more detailed and structured logging than the default . NET logging library. Serilog can be used to log information about application events, errors, and performance metrics.
Install required NuGet packeges, open the Package Manager Console
and type
Install-Package Serilog
Install-Package Serilog.Sinks.File
Create new static class with name logger
that will have Serilog configuration
public static class Logger
{
private static readonly ILogger _errorLogger;
static Logger()
{
_errorLogger = new LoggerConfiguration()
.WriteTo.File(HttpContext.Current.Server.MapPath("~/logs/log-.txt"), rollingInterval: RollingInterval.Day)
.CreateLogger();
}
public static void LogError(string error)
{
_errorLogger.Error(error);
}
}
Use logger
class when you want to log error as below
Logger.LogError("Test error log!");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With