Cosmos Logging Save

Logging component for .NET Core with nice APIs for developers to use.

Project README


Logging component for .NET Core with nice APIs for developers to use. Cosmos.Logging is support for structured logging message in several kinds of .NET applications.

This repository belongs to Cosmosloops Labs..

Nuget Packages


Install the package

Install-Package Cosmos.Logging

Install the specific sink packages, renderer packages or extension packages that you need.

Work in console

Install console package first:

Install-Package Cosmos.Logging.RunsOn.Console

then: (in this case we integrated NLog sink)

static void Main(string[] args)
    //load configuration info
    var root = new ConfigurationBuilder()
        .AddJsonFile("appsettings.json", true, true)

    //initialize logger

    //submit log manually
    var logger1 = LOGGER.GetLogger<Program>(mode: LogEventSendMode.Manually);
    logger1.LogWarning("hello, {$Date} {$MachineName}");

    //or submit log automatically
    var logger2 = LOGGER.GetLogger<Program>();

    //get a future logger
    var logger3 = LOGGER.GetLogger<Program>().ToFuture();

    //or convert a normal to future logger
    var logger4 = logger2.ToFuture();

    //or get a future logger directly
    var logger5 = FUTURE.GetFutureLogger<Program>();

    //and how to use future logger via a nice fluent api
        .SetMessage("future log===> Nice {@L}")
        .SetTags("Alex", "Lewis")
        .SetParameter(new {L = "KK2"})
        .SetException(new ArgumentNullException(nameof(args)))

    //or you can use a optional-parameters-style api in your Application-Framework
        Fields.Message("future log===> Nice {@L}"),
        Fields.Tags("Alex", "Lewis"),
        Fields.Args(new {L = "KK3"}),
        Fields.Exception(new ArgumentNullException(nameof(args)))).Submit();

Work with Microsoft ASP.NET Core Mvc

Install aspnetcore package first:

Install-Package Cosmos.Logging.RunsOn.AspNetCore

then write code in Startup.cs: (in this case, we integrated SqlSugar ORM)

public void ConfigureServices(IServiceCollection services)

    services.AddCosmosLogging(Configuration, config => config
            .ToGlobal(o => o.UseMinimumLevel(LogEventLevel.Information))
            .AddDatabaseIntegration(o => o.UseSqlSugar(sugar => sugar.UseAlias("Everything", LogEventLevel.Verbose)))


finally, just to writing your code:

public class HomeController : Controller
    private readonly ILoggingServiceProvider _loggingProvider;

    public HomeController(ILoggingServiceProvider loggingProvider) {
        _loggingProvider = loggingProvider ?? throw new ArgumentNullException(nameof(loggingProvider));

    // GET
    public IActionResult Index() {
        var log = _loggingProvider.GetLogger<HomeController>();
        log.LogInformation("Nice @ {$Date}");
        return Content("Nice");

Work with Microsoft ASP.NET Mvc

Install aspnet package first:

Install-Package Cosmos.Logging.RunsOn.AspNet

or (if you use Autofac as your default IoC container)

Install-Package Cosmos.Logging.RunsOn.AspNet.WithAutofac


//in Global.asax.cs
public class Global : HttpApplication
    this.RegisterCosmosLogging(s => s.ToGlobal(c => c.UseMinimumLevel(LogEventLevel.Verbose)).AddSampleLog());


People or projects that have made a great contribution to this project:

  • The next one must be you

Organizations and projects

  • The next one must be yours


Member project of Cosmosloops Labs..

Apache License 2.0

Open Source Agenda is not affiliated with "Cosmos Logging" Project. README Source: cosmos-loops/cosmos-logging
Open Issues
Last Commit
8 months ago

Open Source Agenda Badge

Open Source Agenda Rating