Ejemplo n.º 1
0
        private static void ConfigureLogging()
        {
            var environment   = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(IO.Folder.CurrentFolder)
                                .AddJsonFile(Path.Combine(IO.Folder.ConfigFolder, "appsettings.json"), optional: false, reloadOnChange: true)
                                .AddJsonFile(
                Path.Combine(IO.Folder.ConfigFolder, $"appsettings.{environment}.json"),
                optional: true)
                                .Build();

            FileSinkOptions fso = ConfigureFileSink(configuration);

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .Enrich.FromLogContext()
                         .Enrich.WithMachineName()
                         .WriteTo.Debug()
                         .WriteTo.Console()
                         .WriteTo.File(fso.PathFormat, rollingInterval: RollingInterval.Day, buffered: true, levelSwitch: fso.LogLevel,
                                       outputTemplate: fso.OutputTemplate, retainedFileCountLimit: fso.RetainedFileCountLimit)
                         .WriteTo.Elasticsearch(ConfigureElasticSink(configuration, environment))
                         .Enrich.WithProperty("Environment", environment)
                         .CreateLogger();
        }
Ejemplo n.º 2
0
        static FileSinkOptions ConfigureFileSink(IConfigurationRoot configuration)
        {
            LogEventLevel   level  = (Serilog.Events.LogEventLevel)Enum.Parse(typeof(Serilog.Events.LogEventLevel), configuration["File:LogLevel"]);
            FileSinkOptions retVal = new FileSinkOptions();

            retVal.LogLevel               = new LoggingLevelSwitch(level);
            retVal.OutputTemplate         = configuration["File:OutputTemplate"];
            retVal.PathFormat             = configuration["File:PathFormat"];
            retVal.RetainedFileCountLimit = int.Parse(configuration["File:RetainedFileCountLimit"]);
            return(retVal);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Create a new instance of <see cref="LocalFileLogPayloadClientProvider"/>.
 /// </summary>
 /// <param name="settings"></param>
 /// <param name="loggingConfiguration"></param>
 public LocalFileLogPayloadClientProvider(IOptions <FileSinkOptions> settings, LoggingConfiguration loggingConfiguration)
 {
     _options = settings == null ? new FileSinkOptions() : settings.Value;
     _loggingConfiguration = loggingConfiguration ?? throw new ArgumentNullException(nameof(loggingConfiguration));
     _fileAstronautCache   = new FileAstronautCache();
 }