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: 20 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 (about 10 years ago)
- Default Branch: dev
- Last Pushed: 2023-08-29T11:53:28.000Z (over 1 year ago)
- Last Synced: 2025-03-26T19:04:40.843Z (about 1 month ago)
- Topics: android, dotnet, ios, serilog, serilog-sink, xamarin
- Language: C#
- Size: 72.3 KB
- Stars: 55
- Watchers: 14
- Forks: 18
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
# Serilog.Sinks.Xamarin [](https://ci.appveyor.com/project/serilog/serilog-sinks-xamarin) [](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.