HaemmerElectronics.SeppPenner.SerilogSinkForPostgreSQL
1.0.3
Prefix Reserved
See the version list below for details.
dotnet add package HaemmerElectronics.SeppPenner.SerilogSinkForPostgreSQL --version 1.0.3
NuGet\Install-Package HaemmerElectronics.SeppPenner.SerilogSinkForPostgreSQL -Version 1.0.3
<PackageReference Include="HaemmerElectronics.SeppPenner.SerilogSinkForPostgreSQL" Version="1.0.3" />
paket add HaemmerElectronics.SeppPenner.SerilogSinkForPostgreSQL --version 1.0.3
#r "nuget: HaemmerElectronics.SeppPenner.SerilogSinkForPostgreSQL, 1.0.3"
// Install HaemmerElectronics.SeppPenner.SerilogSinkForPostgreSQL as a Cake Addin #addin nuget:?package=HaemmerElectronics.SeppPenner.SerilogSinkForPostgreSQL&version=1.0.3 // Install HaemmerElectronics.SeppPenner.SerilogSinkForPostgreSQL as a Cake Tool #tool nuget:?package=HaemmerElectronics.SeppPenner.SerilogSinkForPostgreSQL&version=1.0.3
SerilogSinkForPostgreSQL
SerilogSinkForPostgreSQL is a library to save logging information from Serilog to PostgreSQL. The assembly was written and tested in .Net Framework 4.8 and .Net Standard 2.0.
Available for
- NetFramework 4.5
- NetFramework 4.6
- NetFramework 4.6.2
- NetFramework 4.7
- NetFramework 4.7.2
- NetFramework 4.8
- NetStandard 2.0
Basic usage:
string connectionString = "User ID=serilog;Password=serilog;Host=localhost;Port=5432;Database=Logs";
string tableName = "logs";
IDictionary<string, ColumnWriterBase> columnWriters = new Dictionary<string, ColumnWriterBase>
{
{ "message", new RenderedMessageColumnWriter(NpgsqlDbType.Text) },
{ "message_template", new MessageTemplateColumnWriter(NpgsqlDbType.Text) },
{ "level", new LevelColumnWriter(true, NpgsqlDbType.Varchar) },
{ "raise_date", new TimestampColumnWriter(NpgsqlDbType.TimestampTz) },
{ "exception", new ExceptionColumnWriter(NpgsqlDbType.Text) },
{ "properties", new LogEventSerializedColumnWriter(NpgsqlDbType.Jsonb) },
{ "props_test", new PropertiesColumnWriter(NpgsqlDbType.Jsonb) },
{ "machine_name", new SinglePropertyColumnWriter("MachineName", PropertyWriteMethod.ToString, NpgsqlDbType.Text, "l") }
};
var logger = new LoggerConfiguration()
.WriteTo.PostgreSQL(connectionString, tableName, columnWriters)
.CreateLogger();
The project can be found on nuget.
Configuration options:
|Parameter|Meaning|Example|Default value|
|-|-|-|-|
|connectionString|The connection string to connect to the PostgreSQL database.|"User ID=serilog;Password=serilog;Host=localhost;Port=5432;Database=Logs"
|None, is mandatory.|
|tableName|The table name to write the data to. Is case-sensitive!|"logs"
|None, is mandatory.|
|period|The time to wait between checking for event batches.|period: new TimeSpan(0, 0, 20)
|00:00:05
|
|formatProvider|The IFormatProvider
to use. Supplies culture-specific formatting information. Check https://docs.microsoft.com/en-us/dotnet/api/system.iformatprovider?view=netframework-4.8.|`new CultureInfo("de-DE")|
null| |columnOptions|The column options to use.|See the examples under the [Full example](https://github.com/SeppPenner/SerilogSinkForPostgreSQL#full-example) section below.|
null| |batchSizeLimit|The maximum number of events to include in a single batch.|
batchSizeLimit: 40|
30| |useCopy|Enables the copy command to allow batch inserting instead of multiple
INSERT commands.|
useCopy: true|
true| |schemaName|The schema in which the table should be created.|
schemaName: "Logs"|
string.Emptywhich defaults to the PostgreSQL
public schema.| |needAutoCreateTable|Specifies whether the table should be auto-created if it does not already exist or not.|
needAutoCreateTable: true|
false| |queueLimit|Maximum number of events in the queue.|
queueLimit: 3000|
int.MaxValueor
2147483647`|
Full example
string connectionString = "User ID=serilog;Password=serilog;Host=localhost;Port=5432;Database=Logs";
string tableName = "logs";
IDictionary<string, ColumnWriterBase> columnOptions = new Dictionary<string, ColumnWriterBase>
{
{ "message", new RenderedMessageColumnWriter(NpgsqlDbType.Text) },
{ "message_template", new MessageTemplateColumnWriter(NpgsqlDbType.Text) },
{ "level", new LevelColumnWriter(true, NpgsqlDbType.Varchar) },
{ "raise_date", new TimestampColumnWriter(NpgsqlDbType.TimestampTz) },
{ "exception", new ExceptionColumnWriter(NpgsqlDbType.Text) },
{ "properties", new LogEventSerializedColumnWriter(NpgsqlDbType.Jsonb) },
{ "props_test", new PropertiesColumnWriter(NpgsqlDbType.Jsonb) },
{ "machine_name", new SinglePropertyColumnWriter("MachineName", PropertyWriteMethod.ToString, NpgsqlDbType.Text, "l") }
};
var logger = new LoggerConfiguration()
.WriteTo.PostgreSQL(connectionString, tableName, columnOptions, needAutoCreateTable: true, schemaName: "LoggingSchema", useCopy: true, queueLimit: 3000, batchSizeLimit: 40, period: new TimeSpan(0, 0, 10), formatProvider: null)
.CreateLogger();
Adjusting column sizes
You can change column sizes by setting the values in the TableCreator
class:
// Sets size of all BIT and BIT VARYING columns to 20
TableCreator.DefaultBitColumnsLength = 20;
// Sets size of all CHAR columns to 30
TableCreator.DefaultCharColumnsLength = 30;
// Sets size of all VARCHAR columns to 50
TableCreator.DefaultVarcharColumnsLength = 50;
Upper or lower case table or column names
Table or column names are always case-sensitive!
Further information:
This project is a fork of https://github.com/b00ted/serilog-sinks-postgresql but is maintained. Do not hesitate to create issues or pull requests.
Change history
- Version 1.0.3.0 (2019-06-23) : Added icon to the nuget package.
- Version 1.0.2.0 (2019-05-13) : Updated documentation, fixed some tests.
- Version 1.0.1.0 (2019-05-08) : Updated documentation, added documentation to the nuget package and all classes, added option to allow upper case table and column names. Simplified building and packing scripts. Added support for NetFramework 4.6, NetFramework 4.6.2, NetFramework 4.7 and NetFramework 4.8.
- Version 1.0.0.0 (2019-02-22) : 1.0 release.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 is compatible. net461 was computed. net462 is compatible. net463 was computed. net47 is compatible. net471 was computed. net472 is compatible. net48 is compatible. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
3.3.7 | 154,593 | 8/29/2021 | |
3.3.6 | 4,898 | 8/9/2021 | |
3.3.5 | 1,370 | 7/25/2021 | |
3.3.4 | 31,952 | 6/4/2021 | |
3.3.3 | 10,157 | 4/29/2021 | |
3.3.2 | 27,537 | 3/4/2021 | |
3.3.1 | 2,682 | 3/4/2021 | |
3.3.0 | 1,836 | 2/21/2021 | |
3.2.4 | 143 | 2/21/2021 | |
3.2.3 | 5,953 | 1/14/2021 | |
3.2.2 | 1,863 | 1/4/2021 | |
3.2.1 | 469 | 1/3/2021 | |
3.2.0 | 541 | 12/26/2020 | |
3.1.0 | 1,230 | 11/16/2020 | |
3.0.0 | 2,455 | 11/11/2020 | |
2.5.0 | 782 | 10/13/2020 | |
2.4.1 | 209 | 10/13/2020 | |
2.4.0 | 4,507 | 9/6/2020 | |
2.3.1 | 279 | 9/6/2020 | |
2.3.0 | 586 | 9/6/2020 | |
2.2.0 | 7,451 | 7/25/2020 | |
2.1.0 | 130,345 | 6/30/2020 | |
2.0.0 | 1,191 | 6/16/2020 | |
1.9.0 | 548 | 6/16/2020 | |
1.8.1 | 569 | 6/5/2020 | |
1.7.0 | 7,508 | 5/10/2020 | |
1.6.0 | 8,863 | 3/26/2020 | |
1.5.0 | 12,651 | 2/9/2020 | |
1.0.4 | 13,268 | 11/8/2019 | |
1.0.3 | 1,032 | 6/23/2019 | |
1.0.2 | 707 | 5/13/2019 | |
1.0.1 | 640 | 5/12/2019 | |
1.0.0 | 636 | 2/22/2019 |
Version 1.0.3.0 (2019-06-23): Added icon to the nuget package.
Version 1.0.2.0 (2019-05-13): Updated documentation, fixed some tests.
Version 1.0.1.0 (2019-02-23): Updated documentation, added documentation to the nuget package and all classes, added option to allow upper case table and column names.
Version 1.0.0.0 (2019-02-22): 1.0 release.