Skip to content

ChangemakerStudios/Common.Logging.Serilog

Repository files navigation

Common.Logging.Serilog

NuGet version Build and Push to Nuget

Common.Logging.Serilog is an adapter that bridges the Common.Logging abstraction with Serilog, allowing you to use Serilog as the underlying logging framework in applications that rely on Common.Logging.

Installation

Install the package via NuGet Package Manager:

Install-Package Common.Logging.Serilog

Or using the .NET CLI:

dotnet add package Common.Logging.Serilog

Getting Started

Configuring Common.Logging

Update your app.config or web.config file to use the Serilog factory adapter:

<configuration>
  <configSections>
    <sectionGroup name="common">
      <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
    </sectionGroup>
  </configSections>

  <common>
    <logging>
      <factoryAdapter type="Common.Logging.Serilog.SerilogFactoryAdapter, Common.Logging.Serilog" />
    </logging>
  </common>
</configuration>

Setting Up Serilog & Usage Example

Configure Serilog and assign it to the global Log.Logger instance:

using Serilog;
using Common.Logging;

class Program
{
    static void Main(string[] args)
    {
        // Configure Serilog: -- Must set global Log.Logger instance
        Log.Logger = new LoggerConfiguration()
            .WriteTo.Console()
            .CreateLogger();

        // Obtain a Common.Logging logger
        var logger = LogManager.GetLogger<Program>();
        logger.Info("Application has started.");

        // Your application code here

        // Ensure to flush and close Serilog at the end
        Log.CloseAndFlush();
    }
}

License

This project is licensed under the MIT License.

About

Bridge from the old to the new logging

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages