Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/NLog/NLog.Targets.MauiLog
- Owner: NLog
- License: bsd-3-clause
- Created: 2022-08-29T05:48:32.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-01-14T14:01:22.000Z (11 months ago)
- Last Synced: 2024-08-31T09:05:08.638Z (3 months ago)
- Topics: csharp, dotnet, logcat, logging, logging-library, maui, netstandard, nlog, nlog-target, nslog, oslog, xamarin, xamarin-android, xamarin-ios
- Language: C#
- Homepage:
- Size: 198 KB
- Stars: 18
- Watchers: 4
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-dotnet-maui - NLog.Targets.MauiLog - square)](https://github.com/NLog/NLog.Targets.MauiLog/stargazers)|[![GitHub last-commit](https://img.shields.io/github/last-commit/NLog/NLog.Targets.MauiLog?style=flat-square)](https://github.com/NLog/NLog.Targets.MauiLog/commits) (Plugins)
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)