Skip to content

[Bug] Serilog + Configuration Templated app does not include initial Serilog Config section #1756

@DevTKSS

Description

@DevTKSS

Current behavior

  • Choosing Serilog + Configuration for creating a new uno app, does not provide a Serilog Configuration Section
  • Current Uno App Template including Serilog produces just the current routes from Navigation Extensions
  • if we set the LogLevel in the always (with any available Logging Feature), included Uno own UseLogging(...) Hostbuilder, this (of course) doesn't affect the Serilog.ILogger behaviour

What we currently get is this here in appsettings.json:

{
  "AppConfig": {
    "Environment": "Production"
  },
  "ApiClient": {
    "UseNativeHandler": true
  }
}

and this here in appsettings.development.json:

{
  "AppConfig": {
    "Environment": "Development"
  },
  "ApiClient": {
    "Url": "https://localhost:5002",
    "UseNativeHandler": true
  }
}

Expected behavior

  • Configureation section for Serilog should be included if we did choose Serilog in a new app
  • LogLevel Switching Support also if we are not using Uno Extensions Logging itself, since we normally should stay with the same pattern AND Uno.Extensions.Logging has NO compartibility Layer for us using Serilog
  • FilePath should be respected from the Uno Serilog extension and if Uno overrides of this silently with IAppHostEnvironment.AppDataPath & HostBuilderExtensions.cs#GetLogFilePath there should be any Notice about this in the Docs!
  • If our Serilog Section from appsettings.json includes Template or our manual HostBuilder configuration includes a ExpressionTemplate, this MUST be respected from the Uno Serilog extension! currently, Users of the Android & iOS TFM's seems to get a not very nice surprise when inspecting the src code used under the hood by the way, same just across all TFM's applyies to the ExpressionTemplate applyed for the Console Logging 🙄
  • Sample configuration could be something like this, which is not included in the Currently by the Uno Extensions Docs linked Serilog/Getting-Started.md wiki:
    {
      "Serilog": {
        "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
        "MinimumLevel": "Debug",
        "WriteTo": [
          { "Name": "Console" },
          {
            "Name": "File",
            "Args": { "path": "%TEMP%/UnoApp4/Logs/log.txt" }
          }
        ],
        "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
        "Properties": {
          "Application": "UnoApp4"
        }
      }
    }

Including those sampled Serilog section and starting our Uno App, does then provide the Logging output WITH content more then the current routes from Navigation Extensions: CUsersSonjasourcesamplesUnoApp4UnoApp4binDebugnet9.0-desktopUnoApp4.exe.txt

Affected platforms

  • iOS
  • Android
  • WebAssembly
  • Skia
  • Windows (WinAppSdk)
  • Server

Template Host

Visual Studio

Host OS

Windows

Template Options

Choosen Serilog, got both logging options (mentioned on #1657 )

    <UnoFeatures>
      Material;
      Hosting;
      Toolkit;
      Logging;
      LoggingSerilog;
      MVUX;
      Configuration;
      HttpRefit;
      Serialization;
      Authentication;
      Navigation;
      SkiaRenderer;
    </UnoFeatures>

Targets: Desktop net 9

Template Version

Uno Extension version 6.2.11.11

Anything else we need to know?

HostBuilder Differences:

  • since the Uno.Extension.Logging.Serilog > HostBuilderExtensions instructs Serilog to read from Configuration, but is not aligning with the common Uno.Extensions.* .Use*(...) Signature. So we can not provide a IConfigurationSection for example, but not even a string sectionName, if we would possibly like to nest our Logging Config into ONE
  • Serilog is also not even aligning with the regular Uno own Logging Framework provided by Uno.Extensions.Logging and based upon Microsoft.Extensions.Logging. For example, Uno.Extensions.Logging does provide those Signatures:
    • .UseLogging(this IHostBuilder hostbuilder, Action<HostbuilderContext,ILoggingBuilder> configure)
    • .UseLogging(this IHostbuilder hostbuilder, Action<LoggingBuilder> configure)

Documentation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't workingtriage/untriagedIndicates an issue requires triaging or verification.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions