[NLog.Targets.MauiLog](https://www.nuget.org/packages/NLog.Targets.MauiLog) for debugging on MAUI / Xamarin Mobile Platforms using the native logging systems:
- **Android** — `Android.Util.Log` → view in **Logcat**
- **iOS / macOS** — `OSLog` → view in **Xcode Console** or **Console.app**
- **Other platforms** — `System.Diagnostics.Debugger.Log` → view in the **debugger output**
## 1. Install NLog
Install the following NuGet packages:
```
dotnet package add NLog.Extensions.Logging
dotnet package add NLog.Targets.MauiLog
```
Use the package versions appropriate for your .NET version (Use ver. 10 for NET10, and ver. 8 for NET8 etc.).
## 2. Configure NLog
NLog integrates with the built-in Microsoft.Extensions.Logging infrastructure. Application code continues to use `ILogger<T>`, while NLog handles log routing, formatting, and writing to configured targets.
Configure NLog in `MauiProgram.cs`:
```csharp
using Microsoft.Extensions.Logging;
using NLog;
using NLog.Extensions.Logging;
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder.Logging.ClearProviders();
// Register NLog MauiLog extension and setup as output target
NLog.LogManager.Setup()
.RegisterMauiLog()
.LoadConfiguration(config => config
.ForLogger()
.FilterMinLevel(NLog.LogLevel.Info)
.WriteToMauiLog());
// Register NLog as Microsoft.Extensions.Logging provider
builder.Logging.AddNLog();
builder.UseMauiApp<App>();
return builder.Build();
}
```
## 3. Start logging
NLog is now configured and receives log events from Microsoft.Extensions.Logging. Application code can continue using `ILogger<T>` as usual.
You are not required to use the `ILogger<T>`, if you prefer using `NLog.LogManager.GetLogger(....)` in the application.
See also [Logging Unhandled Exceptions](https://github.com/NLog/NLog.Targets.MauiLog/wiki/Logging-Unhandled-Exceptions)
See also [Alternative configuration files](https://www.nuget.org/packages/NLog.Targets.MauiLog#readme-body-tab) using appsettings.json or NLog.config as `Embedded resource`.
[NLog.Targets.MauiLog](https://www.nuget.org/packages/NLog.Targets.MauiLog) for debugging on MAUI / Xamarin Mobile Platforms using the native logging systems:
- **Android** — `Android.Util.Log` → view in **Logcat**
- **iOS / macOS** — `OSLog` → view in **Xcode Console** or **Console.app**
- **Other platforms** — `System.Diagnostics.Debugger.Log` → view in the **debugger output**
## 1. Install NLog
Install the following NuGet packages:
```
dotnet package add NLog.Extensions.Logging
dotnet package add NLog.Targets.MauiLog
```
Use the package versions appropriate for your .NET version (Use ver. 10 for NET10, and ver. 8 for NET8 etc.).
## 2. Configure NLog
NLog integrates with the built-in Microsoft.Extensions.Logging infrastructure. Application code continues to use `ILogger<T>`, while NLog handles log routing, formatting, and writing to configured targets.
Configure NLog in `MauiProgram.cs`:
```csharp
using Microsoft.Extensions.Logging;
using NLog;
using NLog.Extensions.Logging;
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder.Logging.ClearProviders();
// Register NLog MauiLog extension and setup as output target
NLog.LogManager.Setup()
.RegisterMauiLog()
.LoadConfiguration(config => config
.ForLogger()
.FilterMinLevel(NLog.LogLevel.Info)
.WriteToMauiLog());
// Register NLog as Microsoft.Extensions.Logging provider
builder.Logging.AddNLog();
builder.UseMauiApp<App>();
return builder.Build();
}
```
## 3. Start logging
NLog is now configured and receives log events from Microsoft.Extensions.Logging. Application code can continue using `ILogger<T>` as usual.
You are not required to use the `ILogger<T>`, if you prefer using `NLog.LogManager.GetLogger(....)` in the application.
See also [Logging Unhandled Exceptions](https://github.com/NLog/NLog.Targets.MauiLog/wiki/Logging-Unhandled-Exceptions)
See also [Alternative configuration files](https://www.nuget.org/packages/NLog.Targets.MauiLog#readme-body-tab) using appsettings.json or NLog.config as `Embedded resource`.