prism-logging-serilog icon indicating copy to clipboard operation
prism-logging-serilog copied to clipboard

Prism 8.0

Open FoxTes opened this issue 4 years ago • 16 comments

Hello. In prism version 8, the ILoggerFacade interface has been removed. Will your library be updated? How to use it now, because the Prism.Logging namespace is no longer there?

FoxTes avatar Dec 04 '20 06:12 FoxTes

Hi Georgy, thanks for reaching out. I haven't looked at Prism v8 in depth yet, but after a cursory look it's not clear to me if there's a replacement for ILoggerFacade - it seems they no longer support logging whatsoever.

How are you currently doing (or planning to do) logging in Prism v8?

Do you think it makes sense to polyfill the ILoggerFacade for v8 in the hope that it would make the upgrade a little easier?

augustoproiete avatar Dec 05 '20 05:12 augustoproiete

At the moment, I do not have a logging system (your library was previously used).

The Prism developers themselves recommend using Prism.Plugin.Logging. But, unfortunately, I don't understand how to use Serilog in this library.

I don't think it makes sense to keep the ILoggerFacade.

FoxTes avatar Dec 05 '20 11:12 FoxTes

I would suggest targeting Prism.Plugin.Logging as the base and implement off of that.

dansiegel avatar Feb 12 '21 16:02 dansiegel

@dansiegel I'm not familiar with Prism.Plugin.Logging but if ILoggerFacade no longer exists in Prism (and there's no internal logging exposed anymore), is there any benefit in using Prism.Plugin.Logging instead of devs using their preferred logging library directly (Serilog, NLog, etc.)?

augustoproiete avatar Feb 12 '21 16:02 augustoproiete

The logging plugin has been around for years. It's independent of Prism but does have helpers to make it easier to register the logger for DI and include multiple providers.

dansiegel avatar Feb 12 '21 17:02 dansiegel

as referenced link https://github.com/PrismLibrary/Prism/issues/2058 use whe ms ILog instead.

wuzhenda avatar Feb 18 '21 01:02 wuzhenda

protected override void RegisterTypes(IContainerRegistry containerRegistry) { var serilogLogger=Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.File(path: "AppLog\\Log.log", encoding: Encoding.UTF8) .CreateLogger(); var appLogger = new SerilogLoggerProvider(serilogLogger).CreateLogger("App"); containerRegistry.RegisterInstance<Microsoft.Extensions.Logging.ILogger>(appLogger); }

` private readonly ILogger _logger;

    public MainWindowViewModel(IContainerExtension Container, IRegionManager regionManager, IEventAggregator eventAggregator, ILogger logger)
    {
        _logger = logger ?? throw new ArgumentNullException(nameof(logger));
        _regionManager = regionManager;
        _container = Container;
        _logger.Log(LogLevel.Debug,"hello,world");
    }`

wuzhenda avatar Feb 18 '21 03:02 wuzhenda

SerilogLoggerProvider from https://github.com/serilog/serilog-extensions-logging

softlion avatar May 07 '21 15:05 softlion

Any update on this one ? Prism team suggests to make use of Prism.Plugin.Logging library but as far as I see it also relies on ILoggerFacade which is retired in latest Prism 8.0. What is the proper way of registering Serilog logger ?

MykolaZaretskyy avatar Jul 02 '21 12:07 MykolaZaretskyy

Any update on this one ? Prism team suggests to make use of Prism.Plugin.Logging library but as far as I see it also relies on ILoggerFacade which is retired in latest Prism 8.0. What is the proper way of registering Serilog logger ?

I found this blog,it can be used it,https://www.andicode.com/prism/wpf/logging/2021/05/21/Logging-In-Prism.html

hongjiapeng avatar Aug 05 '21 01:08 hongjiapeng

Any update on this one ? Prism team suggests to make use of Prism.Plugin.Logging library but as far as I see it also relies on ILoggerFacade which is retired in latest Prism 8.0. What is the proper way of registering Serilog logger ?

I found this blog,it can be used it,https://www.andicode.com/prism/wpf/logging/2021/05/21/Logging-In-Prism.html

That works like a charm. :-) Thanks

bferdinandus avatar Aug 11 '21 10:08 bferdinandus

@hongjiapeng @bferdinandus you can save yourself a lot of trouble as Prism.Container.Extensions gives you Microsoft.Extensions.DependencyInjection extensions to support using registration methods that you need.

dansiegel avatar Aug 11 '21 14:08 dansiegel

@dansiegel thanks for the hint. Indeed it's much easier.

protected override IContainerExtension CreateContainerExtension()
{
    IContainerExtension containerExtension = base.CreateContainerExtension();

    containerExtension.RegisterServices(services => {
        services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog(dispose: true));
    });

    return containerExtension;
}

bferdinandus avatar Aug 11 '21 15:08 bferdinandus

@bferdinandus @dansiegel, I just tried CreateContainerExtension() override using the stuff from Prism.Container.Extensions, but throws an exception about "No public constructor is available for type System.IServiceProvider." (see details here).

When I try the same using the previous method, it works fine.

Is there anything else that needs to be done besides the CreateContainerExtension() override in your last snipped?

FWIW, I am using .net5.0.

angelotrivelli avatar Sep 22 '21 21:09 angelotrivelli

To spark interest in this conversation again, I'd like to continue showcasing Prism.Logging.Serilog in the Prism.Avalonia sample, as we too are about to complete the upgrade to Prism v8.1.

DamianSuess avatar Jul 09 '22 15:07 DamianSuess

@bferdinandus @dansiegel, I just tried CreateContainerExtension() override using the stuff from Prism.Container.Extensions, but throws an exception about "No public constructor is available for type System.IServiceProvider." (see details here).

When I try the same using the previous method, it works fine.

Is there anything else that needs to be done besides the CreateContainerExtension() override in your last snipped?

FWIW, I am using .net5.0.

I know it's quite late to the party but I just wanted to share a solution to the problem that @angelotrivelli was facing. I was able to solve the problem with the missing public constructor for the System.IServiceProvider. Maybe someone else reading this thread might benefit from this. Just note that I am using the Unity container in my WPF app that leverages the Prism library.

protected override IContainerExtension CreateContainerExtension()
{
    var services = new ServiceCollection();
    services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog());
    services.AddHttpClient();
	
    var container = new UnityContainer();
    container.BuildServiceProvider(services);

    return new UnityContainerExtension(container);
}

I also had to reference the following NuGet packages to get this working:

fectus avatar Jun 27 '23 14:06 fectus