Skip to content

devinSpitz/Serilog.Sinks.LiteDb.Async

Repository files navigation

CodeFactor NuGet stable version Discord

Serilog.Sinks.LiteDb.Async

A lightweight high performance Serilog sink that writes to LiteDb database.

Getting started

Install Serilog.Sinks.LiteDb.Async from NuGet

Install-Package Serilog.Sinks.LiteDb.Async

Configure logger

in the Program.cs:

        public static void Main(string[] args)
        {
            var configSettings = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json")
                .Build();

            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                .ReadFrom.Configuration(configSettings)
                .WriteTo.LiteDbAsync(configSettings.GetConnectionString("DefaultConnection")) // This line does active the db logging
                .CreateBootstrapLogger();
            
            Log.Information("Starting up!");

            try
            {
                CreateHostBuilder(args).Build().Run();

                Log.Information("Stopped cleanly");
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "An unhandled exception occured during bootstrapping");
                throw;
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }

And

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .UseSerilog() // This line activates Serilog
                .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });

You can also hardcode the connectionString:

    .WriteTo.LiteDbAsync("Filename=Database.db;Connection=shared;") 

You will find more examples in the repo:

PavlovRconWebserver

ps. currently only on the TestBranch.

Donate:

Feel free to support my work by donating:

Donate with PayPal

Business:

For business inquiries please use:

devin@spitzen.solutions

References:

I started with https://github.com/saleem-mirza/serilog-sinks-sqlite and adapted it to liteDb.Async.

Where to use it ?

  • Great for small and medium size AspNetCore Websites,

License

MIT

About

Serilog event sink that writes to LiteDb database

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages