NuGet package...
install-package d60.SerilogHelpers -ProjectName MyApp
initialize...
Logging.Initialize("myApp", "local");
get a static readonly ILogger in each class that needs to log stuff
public class MyRequestHandler : IRequestHandler<SomeRequest>
{
static readonly ILogger Log = Logging.GetCurrentClassLogger();
public Response Handle(SomeRequest request) {
Log.Info("Turning on something for {SomeId} now",
request.SomeId);
ActuallyDoIt(request.SomeId);
return Ok();
}
void ActuallyDoIt(int someId) { ... }
}
Logging.Initialize("myApp", AppSettings.Environment.ToString(),
password: "myPassword",
mode: AppSettings.Environment == Env.Local
? Logging.Mode.DoNotShipLogs
: Logging.Mode.ShipLogsToAggregator,
configurationCustomizer: config =>
{
config.Enrich.With(new HttpRequestIdEnricher());
config.Enrich.With(new HttpRequestRawUrlEnricher());
config.Enrich.With(new CorrelationIdEnricher(() =>
{
...
return correlationId.ToString();
}));
if (AppSettings.Environment == Env.Local)
{
config.EnableTraceLogging();
config.EnableRollingFiles();
}
else
{
config.EnableErrorMails(...);
}
});
first option
Pros:
Cons:
actual choice
Pros:
Cons:
“Apache is like Microsoft Word, it has a million options but you only need six. nginx does those six things, and it does five of them 50 times faster than Apache.” -- Chris Lea
Stats: