Skip to content

jokokko/serilog-sinks-marten

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serilog.Sinks.Marten Build Status NuGet Version

Send log events to PostgreSQL via Marten.

Package Serilog.Sinks.Marten | Platforms .NET 4.6, .NET Standard 1.3

Getting started

Install the Serilog.Sinks.Marten package from NuGet:

Install-Package Serilog.Sinks.Marten -Pre

Enable & configure the sink through one of the LoggerSinkConfiguration.Marten extension methods:

// Persist logs through the provided IDocumentStore.
var log = new LoggerConfiguration().WriteTo.Marten(store).CreateLogger();
// Or provide a connection string in place of store.

Without further customizations, logs are persited in the Marten Document Store as LogEntryDocument documents, indexed by primary key of type long. Any customizations to the IDocumentStore are respected.

More advanced scenarios are attainable through the IMartenLogWriterBuilder configuration callback. The following sample demonstrates persisting events in the Marten Event Store, whereby the document tenancy of "logs" is used for logged events with error level logs being indexed by the stream identify of "error", whereas other levels are indexed by the identify of "other".

var log = new LoggerConfiguration()
        .WriteTo.Marten(store, c =>
        {
            c.UseTenancy("logs");
            c.UseEventStore(e => e.Level == LogEventLevel.Error ? "error" : "other");
        })
        .CreateLogger();

Note: By default, documents in the Marten Document Store are created through the bulk insertion API. The default Marten Event Store loggers enlist in a Marten LightweightSession (i.e. no document tracking) to persist any logged event batches within a single transaction.

Integration tests (against PostgreSQL) only run if marten_testing_database environment variable is set (e.g. host=localhost;database=marten_test;password=marten;username=marten).

About

A Serilog sink that writes events to PostgreSQL via Marten

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published