Client-Side Logging in .NET MAUI with MetroLog.Maui

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ส.ค. 2024
  • Adding logging to your .NET MAUI application has never been easier with MetroLog.Maui! Enable the logging in your MauiProgram and you can start implementing those log statements which you can then send to in-memory or even text files. As a cherry on the cake we get the "Shake to display logs" functionality out of the box 🤯
    💝 Join this channel to get access to perks:
    th-cam.com/channels/ral.html...
    Disclaimer: this channel is done on personal title, in my free time, and not officially affiliated with or endorsed by Microsoft (my employer) in any way. Opinions and views are my own.
    🛑 Don't forget to subscribe to my channel for more cool content: th-cam.com/users/GeraldVerslui...
    🐦 Follow me on Twitter: / jfversluis
    🤝 Join the Discord server: / discord
    🔗 Links
    Sample Code Repo: github.com/jfversluis/MauiMet...
    MetroLog.Maui Repo: github.com/roubachof/MetroLog
    .NET MAUI Docs: docs.microsoft.com/dotnet/maui/
    ⏱ Timestamps
    00:00 - Client-Side Logging in .NET MAUI with MetroLog.Maui
    00:12 - Why (Client-Side) Logging?
    01:25 - Add MetroLog.Maui to .NET MAUI App
    02:25 - Initialize Logging
    04:32 - Use ILogger Through Dependency Injection
    06:53 - See Runtime Log Statements
    07:58 - Implement Shake to Display Logs
    14:02 - How To Use This Logging in Real-World?!
    🎥 Video edited with Filmora
    🙋‍♂️ Also find my...
    Blog: blog.verslu.is
    Twitch: / jfversluis
    All the rest: jfversluis.dev
    #dotnetmaui #logging #metrolog #dotnet6 #maui
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 52

  • @jfversluis
    @jfversluis  2 ปีที่แล้ว +3

    What? Video already over?! No worries, binge more .NET MAUI content right here ✨th-cam.com/video/o5X5yXdWpuc/w-d-xo.html

  • @fieryscorpion
    @fieryscorpion 2 ปีที่แล้ว +9

    That was pretty neat. Thanks!
    Can you do a follow up video on how to setup the app in a way that if app crashes they get this little dialog saying 'Send crash details to developer?' and retrieve those logs?

  • @mustaphayusuf6091
    @mustaphayusuf6091 2 ปีที่แล้ว +1

    Good work mr Gerald.

  • @josedonizeteoliveirajunior1744
    @josedonizeteoliveirajunior1744 2 ปีที่แล้ว +2

    excellent content, thanks

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว +1

      Much appreciated!

  • @UzairAli001
    @UzairAli001 ปีที่แล้ว

    Thanks for sharing this

    • @jfversluis
      @jfversluis  ปีที่แล้ว

      You’re very welcome Uzair!

  • @ralphcompton4551
    @ralphcompton4551 6 หลายเดือนก่อน +1

    I would like to see whether there has been an improvement for connecting Pages to the ILogger, since this video was made.

  • @gerocsolutionsltd456
    @gerocsolutionsltd456 ปีที่แล้ว

    is there any options to filter the logs, is it possible, if we only want to see the logs which we print?

  • @igor5379
    @igor5379 ปีที่แล้ว

    thanks!

    • @jfversluis
      @jfversluis  ปีที่แล้ว +1

      You’re welcome!

  • @engineerchaos8424
    @engineerchaos8424 ปีที่แล้ว

    Great video. What if you don't want to do dependency injection? How do you create an instance of ILogger in the class more dynamically?

    • @jfversluis
      @jfversluis  ปีที่แล้ว +1

      Create your own static field or class that you want to use. To be honest, I think you should be using dependency injection though!

  • @user-kv8gm1bc3b
    @user-kv8gm1bc3b 10 หลายเดือนก่อน

    Thank you for your work Gerald, I really appreciate these videos...just one question.. how do you cast your real phone to the windows screen like you do on the video?... I'm curious about that, would be very useful sometimes

    • @jfversluis
      @jfversluis  10 หลายเดือนก่อน

      How To Mirror Your Phone to Desktop? 🖥️

  • @igoruhagel
    @igoruhagel 2 หลายเดือนก่อน

    Чувак, Ты супер 👍👍👍

  • @code5877
    @code5877 ปีที่แล้ว

    Hi, great video! Do you think it would be possible to use this and save two seperate files of different logging levels? Example: One logfile only checks for Errors, whilst another logfile is saved which saves everything from warning to critical?

    • @jfversluis
      @jfversluis  ปีที่แล้ว +1

      I think that should definitely be possible!

    • @code5877
      @code5877 ปีที่แล้ว

      @@jfversluis Okay, I'm kinda new to C# and want to have logging on 2 different .xaml.cs files. How do I set it up to get the logging on both of these classes? Right now one is a mainPage and with a button click I redirect to another page. Issue with dependency injection is i need to have a logger as a constructor argument. Anyway around that?

  • @mohammedalsabahii2
    @mohammedalsabahii2 2 ปีที่แล้ว

    Thank you for this cool content ,, I can improve app performance using this plugin right ?

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว +2

      You could use it to identify places where you could improve your performance. This plugin will only just help you with the logging :)

    • @mohammedalsabahii2
      @mohammedalsabahii2 2 ปีที่แล้ว

      @@jfversluis that's awesome

  • @robertholl8914
    @robertholl8914 ปีที่แล้ว

    Just been playing with this over today and having an issue with no error logging going to the console just failing silently and continues. I can get the exceptions by wrapping everything in a try catch, but this isn't a solution. Any thoughts!?

    • @jfversluis
      @jfversluis  ปีที่แล้ว

      Hard to say without seeing any code. If you think there is an issue somewhere, make a small reproduction project and report it on the plugin repository

    • @robertholl8914
      @robertholl8914 ปีที่แล้ว

      @@jfversluis Thanks for the reply. This issue is OOTB, a few examples:
      builder.Services.AddTransient();
      // builder.Services.AddTransient();

  • @gerocsolutionsltd456
    @gerocsolutionsltd456 ปีที่แล้ว

    Where is the place where it captures the shake event. how does the app know log should be generated on shake?

    • @gerocsolutionsltd456
      @gerocsolutionsltd456 ปีที่แล้ว

      it only works on phone and not emulator

    • @jfversluis
      @jfversluis  ปีที่แล้ว

      There is a setting for it. More information here: www.sharpnado.com/metrolog-maui/

  • @tech-man8751
    @tech-man8751 ปีที่แล้ว

    Does App Center or Datadog supports MAUI logging?

    • @jfversluis
      @jfversluis  ปีที่แล้ว

      App Center is working on support!

  • @nalka1102
    @nalka1102 ปีที่แล้ว

    I can't find the issue you mention at 05:00 (and the bug is still here) on dotnet/maui, is it reported on an other repository ? Could you link me that issue if you remember where it is ?

    • @jfversluis
      @jfversluis  ปีที่แล้ว

      It’s not a big in .NET MAUI but this plugin: github.com/roubachof/MetroLog/issues/2
      Also it doesn’t seem to be a bug :)

    • @nalka1102
      @nalka1102 ปีที่แล้ว

      @@jfversluis Well I met the same issue without using the plugin so as the discussion in the issue you linked says, it's more on Microsoft's end.
      It may not be a bug but it would be convenient if you could use both ILogger or ILogger. Anyways, I will just use ILogger, thanks for your quick answer :)

  • @tobination979
    @tobination979 2 ปีที่แล้ว

    Hi Gerald,
    I have a question. Could you make a viedo about AutofillIn for Andorid in Xamarin. I read articles about it but I couldn't figure out. I tried to get an answer on Stackoverflow but nobody could help me. I would really preshiate it.

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว

      I’m not sure what “auto fill in” is :)

    • @tobination979
      @tobination979 2 ปีที่แล้ว

      @@jfversluis That's a Tool which is often used for passwords or adresses. Maybe you knoe it from Google when you can just select a box and it autofills all asked fields. It also saves passwords when you write them down.

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว

      @@tobination979 Hm interesting that it doesn’t just work out of the box

  • @davidjackson148
    @davidjackson148 หลายเดือนก่อน

    How would you get at that log externally ?

    • @jfversluis
      @jfversluis  หลายเดือนก่อน

      I guess you can create a sink to call an external service or hook into the events and files there to send those back to a server

  • @PatrikVesterberg
    @PatrikVesterberg ปีที่แล้ว

    Do you know if it is possible to send logs to a server. For example Grafana?

    • @jfversluis
      @jfversluis  ปีที่แล้ว +1

      Sure, if you setup a custom sink I suppose you could do that!

    • @PatrikVesterberg
      @PatrikVesterberg ปีที่แล้ว

      @@jfversluis Thank you for your input. I will experiment later this week to find out 👍

    • @jfversluis
      @jfversluis  ปีที่แล้ว

      @@PatrikVesterberg let me know how it goes!

  • @VicEstampida
    @VicEstampida ปีที่แล้ว

    Hi, Great video! Actually this isn´t working at least on my x-cover 5 device. I downloaded your sample repo and when I shake the phone: System.InvalidOperationException: 'Current Root View cannot be null'. If someonae is having the same issue we can share the answer here (if we can solve. At this moment no luck). Thank you all!

    • @jfversluis
      @jfversluis  ปีที่แล้ว

      Interesting! Make sure to check the issues on the plugin repo and maybe report it there too

    • @VicEstampida
      @VicEstampida ปีที่แล้ว

      @@jfversluis Solved! Just update VS to 17.4 preview. Thanks!

    • @jfversluis
      @jfversluis  ปีที่แล้ว

      @@VicEstampida Perfect, thanks for letting me know!

  • @mkgungor
    @mkgungor ปีที่แล้ว +1

    Another way of using the library th-cam.com/video/8CPXDHQlBa0/w-d-xo.html

    • @jfversluis
      @jfversluis  ปีที่แล้ว +1

      Thanks for sharing!

  • @vintaatlanta6990
    @vintaatlanta6990 2 ปีที่แล้ว

    serilog may more suitable for .NET app

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว

      I don’t think it’s made compatible for .NET MAUI :)