All Projects → tagcode → serilog-settings-reloader

tagcode / serilog-settings-reloader

Licence: Apache-2.0 license
Adds feature to completely reload serilog settings. Also contains switchable ILogger implementation.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to serilog-settings-reloader

serilog-sinks-browserhttp
Serilog sink for client-side Blazor, with matching ASP.NET Core server relay
Stars: ✭ 36 (+125%)
Mutual labels:  serilog
serilog-sinks-xamarin
A Serilog sink that writes events to Xamarin mobile targets
Stars: ✭ 46 (+187.5%)
Mutual labels:  serilog
Serilog.Sinks.MicrosoftTeams.Alternative
Serilog.Sinks.MicrosoftTeams.Alternative is a library to save logging information from Serilog to Microsoft Teams.
Stars: ✭ 21 (+31.25%)
Mutual labels:  serilog
CleanArchitecture-Template
This is a solution template for Clean Architecture and CQRS implementation with ASP.NET Core.
Stars: ✭ 60 (+275%)
Mutual labels:  serilog
serilog-enrichers-clientinfo
Enrich logs with client IP and UserAgent.
Stars: ✭ 42 (+162.5%)
Mutual labels:  serilog
serilog-sinks-slackclient
Slack Sink for Serilog
Stars: ✭ 24 (+50%)
Mutual labels:  serilog
TelephoneDirectory
microservices-> .net 6, golang - Docker, Ocelot, RabbitMq, MassTransit, mssql, postgresql, elasticsearch, kibana, jwt
Stars: ✭ 40 (+150%)
Mutual labels:  serilog
resharper-structured-logging
An extension for ReSharper and Rider that highlights structured logging templates and contains some useful analyzers
Stars: ✭ 117 (+631.25%)
Mutual labels:  serilog
arcus.observability
Observability with Microsoft Azure in a breeze.
Stars: ✭ 24 (+50%)
Mutual labels:  serilog
Kodkod
https://github.com/alirizaadiyahsi/Nucleus Web API layered architecture startup template with ASP.NET Core 2.1, EF Core 2.1 and Vue Client
Stars: ✭ 45 (+181.25%)
Mutual labels:  serilog
seq-forwarder
Local collection and reliable forwarding of log data to Seq
Stars: ✭ 43 (+168.75%)
Mutual labels:  serilog
serilog-sinks-richtextbox
A Serilog sink that writes log events to a WPF RichTextBox control with colors and theme support
Stars: ✭ 48 (+200%)
Mutual labels:  serilog
serilog-sinks-seq
A Serilog sink that writes events to the Seq structured log server
Stars: ✭ 132 (+725%)
Mutual labels:  serilog
Sitko.Core
Sitko.Core is a set of libraries to help build .NET Core applications fast
Stars: ✭ 46 (+187.5%)
Mutual labels:  serilog
Serilog
Simple .NET logging with fully-structured events
Stars: ✭ 5,000 (+31150%)
Mutual labels:  serilog
PoShLog
🔩 PoShLog is PowerShell cross-platform logging module. It allows you to log structured event data into console, file and much more places easily. It's built upon great C# logging library Serilog - https://serilog.net/
Stars: ✭ 108 (+575%)
Mutual labels:  serilog
ASPNETcoreAngularJWT
Angular in ASP.NET Core with JWT solution by systemjs
Stars: ✭ 48 (+200%)
Mutual labels:  serilog
Akka.Logger.Serilog
Akka.NET logging integration for Serilog library
Stars: ✭ 22 (+37.5%)
Mutual labels:  serilog
serilog-sinks-sentry
A Sentry sink for Serilog
Stars: ✭ 34 (+112.5%)
Mutual labels:  serilog
serilog-sinks-grafana-loki
A Serilog sink sending log events to Grafana Loki
Stars: ✭ 55 (+243.75%)
Mutual labels:  serilog

Serilog.Settings.Reloader

Serilog.Settings.Reloader provides completely reloadable settings for Serilog.

Links:

SwitchableLogger is assigned with new root ILogger when configuration is modified.

// Create switchable
SwitchableLogger switchableLogger = new SwitchableLogger();
// Assign SwitchableLogger to Serilog.Log.Logger
Serilog.Log.Logger = switchableLogger;

// Assign logger to switchableLogger
switchableLogger.Logger = new Serilog.LoggerConfiguration()
        .MinimumLevel.Verbose()
        .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3} {SourceContext}] {Message:lj}{NewLine}{Exception}")
        .CreateLogger();

// Create logger
ILogger logger = Serilog.Log.ForContext<Program>();

// Write
logger.Information("Hello World");

// Reconfigure 
ILogger newLogger = new Serilog.LoggerConfiguration()
        .MinimumLevel.Verbose()
        .WriteTo.Console(outputTemplate: "[{SourceContext}] {Message:lj}{NewLine}{Exception}")
        .CreateLogger();
// Assign new logger
switchableLogger.Set(newLogger, disposePrev: true);

// Write with the previous logger instance, but with different settings
logger.Information("Hello world again");



.AddSerilogConfigurationLoader() can be used with dependency injection's ILoggingBuilder.

// Read configuration
IConfigurationRoot configuration = new ConfigurationBuilder()
    Add(config)
    .Build();

// Service collection
IServiceCollection serviceCollection = new ServiceCollection()
    .AddLogging(loggingBuilder =>
        {
            SwitchableLogger switchableLogger = new SwitchableLogger();
            loggingBuilder
                .ClearProviders()
                .AddSerilog(switchableLogger, true)
                .AddSerilogConfigurationLoader(configuration, switchableLogger);
        });

// Services
using (var services = serviceCollection.BuildServiceProvider())
{
    // Create logger
    Microsoft.Extensions.Logging.ILogger logger = services.GetService<Microsoft.Extensions.Logging.ILogger<Program>>();

    // Write
    logger.LogInformation("Hello World");

    // Modify config
    config.Set("Serilog:WriteTo:0:Args:OutputTemplate", "[{SourceContext}] {Message:lj}{NewLine}{Exception}");
    configuration.Reload();

    // Write with the previous logger instance, but with different settings
    logger.LogInformation("Hello world again");
}



.AddSerilogConfigurationLoader(IConfiguration, SwitchableLogger, Func<IConfiguration, ILogger>) third argument specifies load function.

loggingBuilder
    .ClearProviders()
    .AddSerilog(switchableLogger, true)
    .AddSerilogConfigurationLoader(configuration, switchableLogger, 
        c => new Serilog.LoggerConfiguration().ReadFrom.Configuration(c).CreateLogger())
    );
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].