[MVUX][Navigation][Serilog][Logging] Provide a way to get the Serilog.ILogger in View Code-Behind
What would you like to be added:
I would like to get my Serilog.ILogger in the Code Behind of my Views (independant on the fact if it's a Dialog or Page or any other UI Element / Framework Element), if I choose <UnoFeatures>LoggingSerilog;</UnoFeatures> in my Project, to get advanced Logging capabilities like Logging to File
Why is this needed:
Currently, the only options I see to get any Logging, is to:
-
accept that I only can get
Uno.Core.Logging(or how you named it exactly, when not choosing the Extensions Logging) -
Uno.Extensions.LoggingWhich are both do not support File Logging as far as I know. If I missed this capability, please tell me how! -
There is no Adapter Layer introduced in the Uno.Extensions.Logging.Serilog Package:
- https://github.com/unoplatform/uno.extensions/issues/2896
- We can not use
this.Log().Information("Some Serilog Logging")or at least:this.Log().Get<Serilog.Logger>().ForContext<MyPage>()because the.Get<T>()is only a object Extension (GenericExtensionsinUno.Extensions.Core) and would attempt to cast the source Uno based ILogger into the Serilog.ILogger, which will dont work of course.
-
Maybe use
IInjectable<Serilog.ILogger>BUT (!) I only seen this beeing used for anIInjectable<INavigator>inDialogsPageandCodeBehindPagecontained in the Samples/Playground App in this Repo. There is exact no information about this in the Docs but its a Public accessor API, so there should be some Information and e.g. a small usage Sample Code which tells us about:- Where we can use it (seems like View code behind?)
- How we should/could use this
- What are the Limitations but also features that adds it?
The Source code of
ContentControlNavigatorandFrameworkElementExtensions(which is the underlying Type of literally almost every UI Element on my prefered Desktop Target possibly) is showing an explicit check case for the View could be Implementing this Interface, so it's defintly a realistic Option that could be used!
Why is this important?
If we (Users) are combining those Uno Features:
-
Mvux -
Navigation- implies that we are registring our Routes of course! -
Hosting(-> DI + Extensions Usage)
We are greeted with those limitation:
- The Mvux as Source Generator can not depend on other Generators. Therefore attempting to
x:Bind VM.SomeProperty , Mode=TwoWaywithout creating another Project just for our Models, we are getting an Exception because of the fact that the Generation is not already finished, so the Type might not exist at this time. - Uno Extensions Navigation does not allow ctor Arguments for our Views! So we can not "just" use the "normal" way anyone else (MVVM Users???) is doing and get the required Service from there
Issued multiple times in the past from different Users of Uno:
- https://github.com/unoplatform/uno.extensions/issues/2608
- https://github.com/unoplatform/uno.extensions/issues/2629
- Subscribing to the
DataContextChangedEvent withVM = args.NewValue as MyViewModelfails on the Extensions Navigator The Navigation Framework doesn't provide our required View Model directly, then instead provides:null->ShellViewModel->null->MyViewModelbecause before the DataContext would finally become our expected View Model and at least I dont know of some kind of CanProceedWithXBindApplyment for thethis.InitializeComponent()in each View's Code Behind, so we are just directly running into aNullReferenceExceptionat Runtime 🤷 So you will understand, that even if our VM could/would realistically have suchILogger, because of our VM is meant to create our Model in the end of initialization, its no realistic Option to just wait for this to complete.
For which Platform:
- [x] iOS
- [x] Android
- [x] WebAssembly
- [x] WebAssembly renders for Xamarin.Forms
- [x] Windows
- [ ] Build tasks