saleem-mirza / serilog-sinks-sqlite

A Serilog sink that writes to SQLite
Apache License 2.0
56 stars 44 forks source link

Add Pragma generic list to be included in SQLite connection string #52

Open EntityBox opened 2 weeks ago

EntityBox commented 2 weeks ago

Adding pragma statements to SQLite is vital for the underlaying database.

By adding a generic list, the end user could add items manually that they would like to tweak on their instance.

Because this relates to logging, it could be easy for the user to add in the pragma_auto_vacuum in the list and ensure there is no need to call the vacuum command after bulk deletes.

This PR is adding List<string> to the configuration extension that passes it through to the connection string to be appended.

Example:

List<string> PragmaItems = new List<string>
{
    {"auto_vacuum=FULL"}
};

and then in the LoggerConfiguration:

.WriteTo.SQLite(System.IO.Path.Combine("C:\SomeDirectory", "SomeSQLiteDB.db"),pragmas: PragmaItems)

The result would end with the SQLiteConnectionStringBuilder from the current default: data source="C:\SomeDirectory\SomeSQLiteDB";journal mode=Memory;synchronous=Normal;cache size=500;page size=4096;max page count=2560 to: data source="C:\SomeDirectory\SomeSQLiteDB";journal mode=Memory;synchronous=Normal;cache size=500;page size=4096;max page count=2560;auto_vacuum=FULL;