Код: Выделить всё
IHostBuilder builder =
new HostBuilder()
.UseSerilog((context, services, configuration) =>
{
LoggerConfiguration loggerConfiguration = new LoggerConfiguration().ReadFrom.Configuration(context.Configuration);
string? identification = context.Configuration["uuid"];
if (!Guid.TryParse(identification, out Guid _))
{
throw new InvalidOperationException($"Identifier '{identification}' is not a proper GUID value");
}
loggerConfiguration
.WriteTo.Async(a => a.File(
path: $"Logs/log.{identification}-.log",
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] [{SourceContext}] {Message}{NewLine}{Exception}",
rollingInterval: RollingInterval.Infinite,
fileSizeLimitBytes: 104857600,
retainedFileCountLimit: 5,
rollOnFileSizeLimit: true))
.WriteTo.Console();
Log.Logger = loggerConfiguration.CreateLogger();
})
.ConfigureAppConfiguration(app => app.SetBasePath(AppContext.BaseDirectory).AddCommandLine(args))
.ConfigureServices((host, services) =>
{
services.AddScoped()
// and some worker that uses that service
});
await builder.RunConsoleAsync();
Код: Выделить всё
using System.Linq.Expressions;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using Serilog;
public class SomeService : ISomeService
{
private readonly ILogger _logger;
public SomeService(ILogger logger)
{
_logger = logger;
}
// some methods
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... nfiguraion