I am trying to use WriteTo.RollingFile with Serilog as the following:
var log = new LoggerConfiguration().WriteTo.RollingFile(
@\"F:\\log
This is how I did it:
private readonly Serilog.ILogger _logger; //= Log.ForContext( "Name", "Weather" );
public WeatherForecastController() {
string subPath = Path.Combine( DateTime.Now.ToString( "yyyy" ), DateTime.Now.ToString( "MM" ) ) + $"/{DateTime.Now.ToString("dd")}_Weather";
_logger = Log.ForContext( "Name", subPath );
}
.UseSerilog( ( hostingContext, loggerConfiguration ) => loggerConfiguration
.ReadFrom.Configuration( hostingContext.Configuration )
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.Map(
"Name",
"Request",
( name, wt ) => {
if (name == "Request")
wt.RollingFile( Path.Combine( $"{hostingContext.Configuration["LogPath"]}/{{Date}}-{name}.txt" ) );
else
wt.File( $"{hostingContext.Configuration["LogPath"]}/{name}.txt" );
} )
);