Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/serilog/serilog-sinks-xamarin
A Serilog sink that writes events to Xamarin mobile targets
https://github.com/serilog/serilog-sinks-xamarin
android dotnet ios serilog serilog-sink xamarin
Last synced: 8 days ago
JSON representation
A Serilog sink that writes events to Xamarin mobile targets
- Host: GitHub
- URL: https://github.com/serilog/serilog-sinks-xamarin
- Owner: serilog
- License: apache-2.0
- Created: 2015-02-22T22:52:16.000Z (over 9 years ago)
- Default Branch: dev
- Last Pushed: 2023-08-29T11:53:28.000Z (about 1 year ago)
- Last Synced: 2024-10-30T00:27:19.630Z (17 days ago)
- Topics: android, dotnet, ios, serilog, serilog-sink, xamarin
- Language: C#
- Size: 72.3 KB
- Stars: 55
- Watchers: 15
- Forks: 18
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
# Serilog.Sinks.Xamarin [![Build status](https://ci.appveyor.com/api/projects/status/8iy9owuib92gvtix?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-xamarin) [![Join the chat at https://gitter.im/serilog/serilog](https://img.shields.io/gitter/room/serilog/serilog.svg)](https://gitter.im/serilog/serilog)
Writes [Serilog](https://serilog.net) events to the console of Xamarin.iOS (NSLog) / Xamarin.Android (AndroidLog).
### Getting started
Install from [NuGet](https://nuget.org/packages/serilog.sinks.xamarin):
```powershell
Install-Package Serilog.Sinks.Xamarin
```When using Xamarin.iOS
```csharp
Log.Logger = new LoggerConfiguration()
.WriteTo.NSLog()
.CreateLogger();
```When using Xamarin.Android
```csharp
Log.Logger = new LoggerConfiguration()
.WriteTo.AndroidLog()
.Enrich.WithProperty(Constants.SourceContextPropertyName, "MyCustomTag") //Sets the Tag field.
.CreateLogger();
```Within your portable class libary or within your application
```csharp
Log.Information("This will be written to either NSLog or AndroidLog");```
Because the memory buffer may contain events that have not yet been written to the target sink, it is important to call `Log.CloseAndFlush()` or `Logger.Dispose()` when the application/activity exits.