serilog / serilog-extensions-logging

Serilog provider for Microsoft.Extensions.Logging
Apache License 2.0
309 stars 99 forks source link

netstandard guidance #108

Closed pshrosbree closed 6 years ago

pshrosbree commented 6 years ago

Is this the package to use if you're building netcoreapp, netstandard or net compilation targets but not using ASP.NET?

nblumhardt commented 6 years ago

Hi Peter,

Great question :-) Yes, and no.

If you're building a .NET Core app without ASP.NET, you can just use Serilog directly, as you would in a regular .NET Framework app.

If you're building a class library for .NET Standard, you can also just use the Serilog package directly. If it's a public shared library and you're not sure of the logger consumers will use, take a look at https://nblumhardt.com/2016/04/which-logging-abstraction-should-i-use/ for some discussion.

Finally, if you decide you want to introduce a logging abstraction through MEL, you can use this package, yes. But, the abstraction does come with a cost - less expressive API and of course the interop itself.

It'd be great to hear more about your scenario, thanks for getting in touch.

pshrosbree commented 6 years ago

I was using Serilog directly, and that worked fine, but then I started using App.Metrics which takes a dependency on Microsoft.Extensions.Logging (amongst other Microsoft.Extensions), so I need to give it a Microsoft.Extensions logger factory, which got me here.

I could switch to Microsoft.Extensions.* completely, but it is really hard to give up both Autofac and the nicer Serilog interface. So for DI I use Autofac with the Microsoft.Extensions.DependencyInjection integration, which is a little messy, but works.

I did have a look at Which logging abstraction should I use? and plan to use LibLog, but have not made that particular switch just yet.

nblumhardt commented 6 years ago

Thanks for the follow-up. Yes, this is the package you need in order to supply a logger factory to App.Metrics, then 👍

Check out https://github.com/nblumhardt/autofac-serilog-integration/ for Serilog + Autofac, if that would help with the DI config.

Cheers!

Mystere commented 6 years ago

@pshrosbree - i'm not sure I understand your point about "giving up" dependency injection. MEL supports injecting loggers into your objects..

pshrosbree commented 6 years ago

@Mystere I saying giving up Autofac (by switching to MEDI) and the Serilog interface (in favour of MEL), not giving up DI.

Mystere commented 6 years ago

@pshrosbree - but you can use any DI container you want with aspnet core.

I understand the argument about the loss of interface, but I was more interested in why you were talking about Autofac.

pshrosbree commented 6 years ago

I am not using ASP.NET at all. I imagine you mean net standard. You do have a wide choice, but MEDI is not as nice as Autofac, and AppMetrics required MEDI and MEL, and wanted to know if this was the package to use for a MEL facade for Serilog if I was not using ASP.NET.

nblumhardt commented 6 years ago

@pshrosbree guessing from the above that your question is answered, please let me know if you need more info/help, though!