how to implement logger and save logs files .net maui 8

Ashutosh Mehere 0 Reputation points
2024-04-29T14:51:11.8266667+00:00

how to implement logger and save logs files .net maui 8

using ChangeBox.Configuration;

using ChangeBox.Handlers;

using ChangeBoxMobileApp.GeneralServices;

using CommunityToolkit.Maui;

using MetroLog.MicrosoftExtensions;

using Microsoft.Extensions.Logging;

using Syncfusion.Maui.Core.Hosting;

namespace ChangeBox;

public static class MauiProgram

{

public static MauiApp CreateMauiApp()

{

    var builder = MauiApp.CreateBuilder();

    builder

        .UseMauiApp<App>()

        .ConfigureSyncfusionCore()

        .UseMauiCommunityToolkit()

        .ConfigureFonts(fonts =>

        {

            fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");

            fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");

            fonts.AddFont("DMSans-Bold.ttf", "DMSansBold");

            fonts.AddFont("DMSans-Regular.ttf", "DMSansRegular");

            fonts.AddFont("DMSans-Medium.ttf", "DMSansMedium");

            fonts.AddFont("Aeonik-Regular.ttf", "AeonikRegular");

        });

    FormHandler.RemoveBorders();

    DependencyInjectionService.Initialize(builder);

    builder.Logging.AddTraceLogger(_ => { });

    builder.Logging.AddInMemoryLogger(_ => { });

    builder.Logging.AddStreamingFileLogger(_ => { });

    builder.Services.AddTransient<MainPage>();

#if DEBUG

    builder.Logging.AddDebug();

#endif

    var test = builder.Build();

    ServiceHelper.Initialize(test.Services);

    return test;

}

}

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,953 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 36,706 Reputation points Microsoft Vendor
    2024-04-30T03:04:24.3066667+00:00

    Hello,

    MAUI uses the API provided by Microsoft.Extensions.Logging for logging operations. According to its documentation, this Package does not provide operations for writing to files.

    For your needs, you'll need to extend Logger with methods that can support writing to files, or use some third-party logging package that supports MAUI. Due to Q&A policies, I can't recommend specific packages.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments