augustoproiete / prism-logging-serilog

Integrate Serilog with Prism in your WPF, UWP, or Xamarin Forms apps
Apache License 2.0
40 stars 2 forks source link

Prism 8.0 #3

Open FoxTes opened 3 years ago

FoxTes commented 3 years ago

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?

augustoproiete commented 3 years ago

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?

FoxTes commented 3 years ago

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.

dansiegel commented 3 years ago

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

augustoproiete commented 3 years ago

@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.)?

dansiegel commented 3 years ago

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.

wuzhenda commented 3 years ago

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

wuzhenda commented 3 years ago

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");
    }`
softlion commented 3 years ago

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

MykolaZaretskyy commented 3 years ago

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 ?

hongjiapeng commented 3 years ago

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

bferdinandus commented 3 years ago

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

dansiegel commented 3 years ago

@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.

bferdinandus commented 3 years ago

@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;
}
angelotrivelli commented 3 years ago

@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.

DamianSuess commented 2 years ago

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.

fectus commented 1 year ago

@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: