Search code examples
c#androidloggingmauimetrolog

How to access generated logs in an Android application?


I am using MetroLogger to generate debug logs in a MAUI application.

I am able to retrieve the logs when running the Windows app but not the Android one. I have tried on a physical phone and on an Emulator with no success. I have searched for documentations but did not find any relevant information about this.

Here is my configuration code:

    builder.Logging
    .AddTraceLogger(
        options =>
        {
            options.MinLevel = LogLevel.Trace;
            options.MaxLevel = LogLevel.Critical;
        }) // Will write to the Debug Output
    .AddInMemoryLogger(
        options =>
        {
            options.MaxLines = 1024;
            options.MinLevel = LogLevel.Debug;
            options.MaxLevel = LogLevel.Critical;
        })
    .AddStreamingFileLogger(
        options =>
        {
            options.RetainDays = 2;
            options.FolderPath = Path.Combine(
                FileSystem.CacheDirectory,
                "MetroLogs");
        });

    var path = FileSystem.CacheDirectory;
    builder.Services.AddSingleton(LogOperatorRetriever.Instance);

FileSystem.CacheDirectory is equal to

/data/user/0/[appcompanyname]/cache

But where should I find that folder ? I have tried:

C:\Users[username].android\avd\pixel_5_-_api_34.avd

Thanks for any help with this


Solution

  • It's not on your device, it's on your phone or emulator. You need to access it on that. The path is the exact path- on that device. You can use adb pull <path> to pull the file, or you can use Device Explorer in Android Studio to access it. I'm sure if you're using Visual Studio there's a similar utility.