Serilog.Sinks.SQLite.Maui

Serilog event sink that writes to SQLite database using SqliteNet-Pcl. The fork of Serilog.Sinks.SQLite https://github.com/saleem-mirza/serilog-sinks-sqlite Referring to this issue saleem-mirza#24 (comment) It can run normally in Maui


Keywords
SQLite, logging, serilog
License
Apache-2.0
Install
Install-Package Serilog.Sinks.SQLite.Maui -Version 1.0.1

Documentation

# Serilog.Sinks.SQLite.Maui

The fork of Serilog.Sinks.SQLite

Referring to this issue saleem-mirza#24 (comment)

It can run normally in Maui

I made the following changes

  • Replace System.Data.SQLite with SQLiteNetPcl
  • Replace Newtonsoft.Json with System.Text.Json
  • add program annotation in LoggerConfigurationSQLiteExtensions.cs. Because there will be an exception where the reference object instance is null in Maui's Android.
//if (!sqliteDbPathUri.IsAbsoluteUri) {
//    var basePath = System.Reflection.Assembly.GetEntryAssembly().Location;
//    sqliteDbPath = Path.Combine(Path.GetDirectoryName(basePath) ?? throw new NullReferenceException(), sqliteDbPath);
//}

Getting started

Install Serilog.Sinks.SQLite.Maui from NuGet

Install-Package Serilog.Sinks.SQLite.Maui

Configure logger by calling WriteTo.SQLite()

var logger = new LoggerConfiguration()
    .WriteTo.SQLite(@"Logs\log.db")
    .CreateLogger();
    
logger.Information("This informational message will be written to SQLite database");