Skip to content

Logging

Logging in Shiny is built into the very core of the framework. We use Microsoft.Extensions.Logging as our abstraction point to allow for all sorts of logging configuration and providers.

With Shiny and especially background services, it is important to know that providers like debug and console won’t work. The reason is simple, when the background delegates/jobs execute, the debugger is not attached. Thus, we recommend using loggers that write to a local file or some online service

Some suggested logging provider nugets:

ProviderNuGet
Shiny.Logging.Sqlite

Logging Within Your App

Within any component that has been registered with your dependency injection container, you can now do the following

using Microsoft.Logging.Extensions;
namespace MyNamespace;
public class MyThing {
public MyThing(ILogger<MyThing> logger)
{
logger.LogInformation("Hello World");
}
}

SQLite

SQLite logging is great for local testing of your background delegates as it doesn’t require much additional setup and a log viewer can be created right inside your app


  using Shiny;

  namespace ShinyApp;
  
  
  public static class MauiProgram
  {
      public static MauiApp CreateMauiApp() 
      {
        var builder = MauiApp
          .CreateBuilder()
          .UseMauiApp<App>()
          .UseShiny() // <-- add this line (this is important)
          .ConfigureFonts(fonts =>
          {
              fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
              fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
          });


      return builder.Build();
    }
  }