A lightweight high performance Serilog sink that writes to LiteDb database.
Install Serilog.Sinks.LiteDb.Async from NuGet
Install-Package Serilog.Sinks.LiteDb.Async
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:
ps. currently only on the TestBranch.
Feel free to support my work by donating:
For business inquiries please use:
- LiteDB - https://github.com/quicksln/LiteDB#
- Async LiteDb - https://github.com/mlockett42/litedb-async#
- Newtonsoft.Json - https://github.com/JamesNK/Newtonsoft.Json#
- Serilog - https://github.com/serilog/serilog#
I started with https://github.com/saleem-mirza/serilog-sinks-sqlite and adapted it to liteDb.Async.
- Great for small and medium size AspNetCore Websites,