Skip to content

Instantly share code, notes, and snippets.

@bitbonk
Last active August 29, 2015 14:23
Show Gist options
  • Save bitbonk/035a7a4fe2e4a792653b to your computer and use it in GitHub Desktop.
Save bitbonk/035a7a4fe2e4a792653b to your computer and use it in GitHub Desktop.
private void ConfigureLogging()
{
this.log = this.loggerConfiguration.CreateLogger().ForContext<DefaultBootstrapper>();
LogManager.GetLog = type => new CaliburnSerilogAdapter(this.log.ForContext(type));
LogContext.PushProperty("a", 1);
this.log.Information("template", this, null, new Uri("http://google.de"));
this.log.ForContext(typeof(string)).Information("template2", this, null, new Uri("http://bing.com"));
}
// Adapter:
using System;
using Caliburn.Micro;
using Serilog;
public class CaliburnSerilogAdapter : ILog
{
private readonly ILogger log;
public CaliburnSerilogAdapter(ILogger log)
{
Ensure.ArgumentNotNull(log, "log");
this.log = log;
}
public void Info(string format, params object[] args)
{
this.log.Information(format, args);
}
public void Warn(string format, params object[] args)
{
this.log.Warning(format, args);
}
public void Error(Exception exception)
{
this.log.Error(exception, "'{ExceptionType}' in Caliburn.Micro: {ExceptionMessage}", exception.GetType(), exception.Message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment