How to persist Serilog.Sinks.Xamarin logs

Viewed 579

Sinks.Xamarin on a xamarin forms app, so far it works great, but I'm looking forward to persist the logs so I can send them to the server later. this are the solutions I have found so far

1) sqlite Serilog.Sinks.SQLite only write once in db in Xamarin Form(Android)

2)Json file Serilog.Extensions.Logging.File

so far I like more the second option but that nuget is for asp.net mvc, is there any option for xamarin forms that persist the log in a file?

1 Answers

This looks like a case of data persistence.

Data can be persisted using Application.Current.Properties.

The Properties dictionary uses a string key and stores an object value.

For instance, you could put the following line in OnDisappearing() in your cs.

Application.Current.Properties ["store"] = someClass.ID;

In the OnStart() or OnResume() methods:

if (Application.Current.Properties.ContainsKey("id"))
{
    var id = Application.Current.Properties ["id"] as int;
    // do something with id
}

Here's some more helpful documentation of this.

Related