maui

MAUI: How we can view debug statements in release mode


I am trying to print the debugger statements on release mode for resolving one issue.

For that I did below changes:

1 Added DebugType, DebugSymbols, Debuggable and AndroidEnableDeveloperInstrumentation on .csproj file.

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-android|AnyCPU'">
  <ApplicationId>com.companyname.appname</ApplicationId>
  <AndroidPackageFormat>apk</AndroidPackageFormat>
  <ApplicationTitle>appname</ApplicationTitle>
  <DebugType>portable</DebugType>
  <DebugSymbols>true</DebugSymbols>
  <Debuggable>true</Debuggable>
  <AndroidEnableDeveloperInstrumentation>true</AndroidEnableDeveloperInstrumentation>
</PropertyGroup>

2 Added android:debuggable="true" in android manifext file under application.

3 Added below code in MAUIProgram.cs.

builder.Logging.AddConsole(options =>
{
    options.IncludeScopes = true;
});
builder.Logging.SetMinimumLevel(LogLevel.Debug);
  1. Under App.xaml.cs added below code.

    using Microsoft.Extensions.Logging;

    public partial class App : Application { public App(ILogger logger) { InitializeComponent();

         logger.LogInformation("App started in production mode.");
         logger.LogError("An error occurred.");
     }
    

    }

  2. Under project properties enabled developer instrumentation for release mode.

enter image description here

But when I run in release mode I am getting below screen.

enter image description here

Is there any other changes to view the debugger statements in release mode?


Solution

  • As I can see from your screenshots you are building for Android. If that is the case, then use

        Console.WriteLine(DebugLine);
    

    Then check logcat for any DOTNET lines. Should look like this: enter image description here