Mvvmcross: Logging : Remove Reflection

Created on 17 Jan 2020  路  4Comments  路  Source: MvvmCross/MvvmCross

馃彈 Enhancement Proposal

Implement a set of plugins for popular log providers rather than looking for assemblies and executing reflection.

Pitch

Right now we have a set of loggers that use reflection. These loggers have public NuGet packages, and can be referenced:

  • EntLib (https://www.nuget.org/packages/EnterpriseLibrary.Logging/)
  • Log4Net (https://www.nuget.org/packages/log4net/)
  • Loupe (https://www.nuget.org/packages/Gibraltar.Agent/)
  • NLog (https://www.nuget.org/packages/NLog/)
  • Serilog (https://www.nuget.org/packages/Serilog/)

To avoid adding all these references to the main project we can create a set of Plugins: each Plugin will contain a logger NuGet package and a particular IMvxLogProvider implementation.

In the Setup class we can return a real Log Provider Type instead of MvxLogProviderType.

Platforms affected (mark all that apply)

  • [x] :iphone: iOS
  • [x] :robot: Android
  • [x] :checkered_flag: WPF
  • [x] :earth_americas: UWP
  • [x] :apple: MacOS
  • [x] :tv: tvOS
  • [x] :monkey: Xamarin.Forms
enhancement

Most helpful comment

I know it will be a big breaking change. However, the main thing you would need to do is to search and replace IMvxLog withILogger.

I wouldn't do this for next minor release, this would probably be for 7.0.0.

Taking the hard dependency on Microsoft.Extensions.Logging will also let us easily integrate with other Microsoft libs. I regard Microsoft.Extensions.Logging as the de-facto way of providing logging in modern .NET Apps.

All 4 comments

I was a actually thinking about rewriting the logging a bit. By adding a dependency on Microsoft.Extensions.Logging and then move the multiple log providers into their own packages and allow implementing logging providers without reflection.

This is similar to what you propose here, except for removal of IMvxLog and IMvxLoggingProvider and depending on Microsoft.Extensions.Logging's ILogger and ILoggerFactory

@Cheesebaron I am not sure about referencing Microsoft.Extensions.Logging:

  1. The main framework and all other plugins/projects/etc will depend on this library
  2. This is a huge refactoring, leading to breaking changes, as IMvxLog is used in almost every component

On the other hand, there are Microsoft.Extensions.Logging's ILogger implementations for almost all loggers we have, so there is no need to have these additional packages with custom log providers.

I know it will be a big breaking change. However, the main thing you would need to do is to search and replace IMvxLog withILogger.

I wouldn't do this for next minor release, this would probably be for 7.0.0.

Taking the hard dependency on Microsoft.Extensions.Logging will also let us easily integrate with other Microsoft libs. I regard Microsoft.Extensions.Logging as the de-facto way of providing logging in modern .NET Apps.

I agree with your point and will start working on this one.

Was this page helpful?
0 / 5 - 0 ratings