A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/NLog/NLog.Targets.MauiLog below:

GitHub - NLog/NLog.Targets.MauiLog: NLog MauiLog Target for writing to Apple Unified Logging OSLog

NLog Target for debugging on MAUI / Xamarin Mobile Platforms:

How to setup NLog in MAUI
  1. Install the NLog packages

    or in your csproj (Use ver. 8 for NET8, and ver. 7 for NET7 etc.):

    <PackageReference Include="NLog.Targets.MauiLog" Version="8.*" />
    <PackageReference Include="NLog.Extensions.Logging" Version="6.*" />
  2. Add NLog to the MauiApp

    Update MauiProgram.cs to include NLog as Logging Provider:

    var builder = MauiApp.CreateBuilder();
    
    // Add NLog for Logging
    builder.Logging.ClearProviders();
    builder.Logging.AddNLog();

    If getting compiler errors with unknown methods, then update using-section:

    using Microsoft.Extensions.Logging;
    using NLog;
    using NLog.Extensions.Logging;
  3. Load NLog configuration for logging

    Add the NLog.config-file into the Application-project as assembly-resource (Build Action = embedded resource), and load like this:

    NLog.LogManager.Setup().RegisterMauiLog()
        .LoadConfigurationFromAssemblyResource(typeof(App).Assembly);

    Alternative setup NLog configuration using fluent-API:

    var logger = NLog.LogManager.Setup().RegisterMauiLog()
                     .LoadConfiguration(c => c.ForLogger().FilterMinLevel(NLog.LogLevel.Debug).WriteToMauiLog())
                     .GetCurrentClassLogger();
Configuration options for MAUI Log Target

Example NLog.config-file:

<nlog>
<extensions>
    <add assembly="NLog.Targets.MauiLog" />
</extensions>
<targets>
    <target name="mauilog" type="MauiLog" />
</targets>
<rules>
    <logger name="*" minLevel="Info" writeTo="mauilog" />
</rules>
</nlog>

See also Logging Unhandled Exceptions


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4