Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/NLog/NLog.Targets.MauiLog

NLog MauiLog Target for writing to Apple Unified Logging OSLog / Android.Util.Log for LogCat
https://github.com/NLog/NLog.Targets.MauiLog

csharp dotnet logcat logging logging-library maui netstandard nlog nlog-target nslog oslog xamarin xamarin-android xamarin-ios

Last synced: 30 days ago
JSON representation

NLog MauiLog Target for writing to Apple Unified Logging OSLog / Android.Util.Log for LogCat

Awesome Lists containing this project

README

        

# NLog.Targets.MauiLog
NLog Target for debugging on MAUI / Xamarin Mobile Platforms:

- Apple iOS / MacOS - Unified Logging OSLog (replacement of print and NSLog)
- Android - Android.Util.Log / LogCat
- NetStandard - System.Diagnostics.Debugger.Log

[![Version](https://badge.fury.io/nu/NLog.Targets.MauiLog.svg)](https://www.nuget.org/packages/NLog.Targets.MauiLog)
[![AppVeyor](https://img.shields.io/appveyor/ci/nlog/nlog-targets-mauilog/master.svg)](https://ci.appveyor.com/project/nlog/nlog-targets-mauilog/branch/master)

## How to setup NLog in MAUI

1) **Install the NLog packages**

- `Install-Package NLog.Targets.MauiLog`
- `Install-Package NLog.Extensions.Logging`

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

```xml


```

2) **Add NLog to the MauiApp**

Update `MauiProgram.cs` to include NLog as Logging Provider:
```csharp
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:
```csharp
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:
```csharp
NLog.LogManager.Setup().RegisterMauiLog()
.LoadConfigurationFromAssemblyResource(typeof(App).Assembly);
```
Alternative setup NLog configuration using [fluent-API](https://github.com/NLog/NLog/wiki/Fluent-Configuration-API):
```csharp
var logger = NLog.LogManager.Setup().RegisterMauiLog()
.LoadConfiguration(c => c.ForLogger().FilterMinLevel(NLog.LogLevel.Debug).WriteToMauiLog())
.GetCurrentClassLogger();
```

## Configuration options for MAUI Log Target

- **Layout** - LogEvent message layout
- **Category** - LogEvent category layout (optional)

Example `NLog.config`-file:

```xml

```

See also [Logging Unhandled Exceptions](https://github.com/NLog/NLog.Targets.MauiLog/wiki/Logging-Unhandled-Exceptions)