Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

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

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.