Skip to content

Instantly share code, notes, and snippets.

@hikalkan
Created January 2, 2016 21:52
Show Gist options
  • Save hikalkan/78a93f4da24666a2e971 to your computer and use it in GitHub Desktop.
Save hikalkan/78a93f4da24666a2e971 to your computer and use it in GitHub Desktop.
Enabling Serilog in an ABP based Web project
//Remove this:
AbpBootstrapper.IocManager.IocContainer
.AddFacility<LoggingFacility>(f => f.UseLog4Net()
.WithConfig("log4net.config")
);
//Add this:
AbpBootstrapper.IocManager.IocContainer.Register(
Component
.For<LoggerConfiguration>()
.UsingFactoryMethod(
() => new LoggerConfiguration() //Configure Serilog here!
.WriteTo.ColoredConsole()
.MinimumLevel.Debug()
).LifestyleSingleton(),
Component
.For<ILoggerFactory, SerilogFactory>()
.ImplementedBy<SerilogFactory>()
.LifestyleSingleton(),
Component
.For<ILogger>()
.UsingFactoryMethod((kernel, componentModel, creationContext) =>
{
return kernel.Resolve<ILoggerFactory>().Create(creationContext.Handler.ComponentModel.Name);
})
.LifestyleTransient()
);
@hikalkan
Copy link
Author

hikalkan commented Jan 2, 2016

Before it, we need to

Install-Package Castle.Core-Serilog

And import some namespaces

using Castle.Core.Logging;
using Castle.MicroKernel.Registration;
using Castle.Services.Logging.SerilogIntegration;
using Serilog;
using ILogger = Castle.Core.Logging.ILogger;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment