Serilog Sink for Nats
Using Nuget:
Install-Package Serilog.Sinks.Nats
To use with ILoggerFactory via dependency injection,
add the following to ConfigureServices in your Startup class.
See the logging documentation
for specific help on using the ILoggerFactory and ILogger<T>.
using Serilog;
using Serilog.Formatting.Json;
using Serilog.Sinks.Nats;
public class Startup
{
private readonly IConfiguration _config;
// ...
public IServiceProvider ConfigureServices(IServiceCollection services)
{
var config = new NatsConfiguration
{
host = _config["NATS_HOST"]
// ...
};
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.Nats(config, new JsonFormatter())
.CreateLogger();
var loggerFactory = new LoggerFactory();
loggerFactory
.AddSerilog()
.AddConsole(LogLevel.Information);
services.AddSingleton<ILoggerFactory>(loggerFactory);
}
// ...
}