PvWay.LoggerService.PgSqlLogWriter.nc6
2.0.3
dotnet add package PvWay.LoggerService.PgSqlLogWriter.nc6 --version 2.0.3
NuGet\Install-Package PvWay.LoggerService.PgSqlLogWriter.nc6 -Version 2.0.3
<PackageReference Include="PvWay.LoggerService.PgSqlLogWriter.nc6" Version="2.0.3" />
paket add PvWay.LoggerService.PgSqlLogWriter.nc6 --version 2.0.3
#r "nuget: PvWay.LoggerService.PgSqlLogWriter.nc6, 2.0.3"
// Install PvWay.LoggerService.PgSqlLogWriter.nc6 as a Cake Addin #addin nuget:?package=PvWay.LoggerService.PgSqlLogWriter.nc6&version=2.0.3 // Install PvWay.LoggerService.PgSqlLogWriter.nc6 as a Cake Tool #tool nuget:?package=PvWay.LoggerService.PgSqlLogWriter.nc6&version=2.0.3
PostgreSQL Log Writer for .Net Core 6 by pvWay
Dependendies
- pvWay.LoggerService.Abstractions.nc6
- Npgsql
Description
This nuGet is a PostgreSQL implementation of the PvWay.LoggerService.Abstractions.nc6 that will persist logs into a table in the PostgreSQL database. This implementation uses the light PostgreSQL DAO nuGet.
Pre-conditions for this service to work properly
The connection string provided should allow inserting rows into a table that should conform to the following DDL.
Log table definition example
-- Table: public.AppLog
-- DROP TABLE IF EXISTS public."AppLog";
CREATE TABLE IF NOT EXISTS public."AppLog"
(
"Id" integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
"UserId" character varying(36) COLLATE pg_catalog."default",
"CompanyId" character varying(36) COLLATE pg_catalog."default",
"SeverityCode" character (1) COLLATE pg_catalog."default" NOT NULL,
"MachineName" character varying(50) COLLATE pg_catalog."default" NOT NULL,
"Topic" character varying(50) COLLATE pg_catalog."default",
"Context" character varying(256) COLLATE pg_catalog."default" NOT NULL,
"Message" text COLLATE pg_catalog."default" NOT NULL,
"CreateDateUtc" timestamp with time zone NOT NULL,
CONSTRAINT "ApplicationLog_pkey" PRIMARY KEY ("Id")
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."AppLog"
OWNER to postgres;
-- Index: ApplicationLog_IX_Topic
-- DROP INDEX IF EXISTS public."ApplicationLog_IX_Topic";
CREATE INDEX IF NOT EXISTS "ApplicationLog_IX_Topic"
ON public."AppLog" USING btree
("Topic" COLLATE pg_catalog."default" ASC NULLS LAST)
TABLESPACE pg_default;
Columns
Id
The Id column is not required and will not be populted by the service. However it might be convenient to have a numeric primary column. If you define this column make sure the database will fill it accordingly by for example using the IDENTITY syntax
UserId
- You can provide your own column name for this column
- The UserId column persists the identification of the connected user if any
- This column should be nullable
- This column should be of type character varying
- The logger will truncate any info exceding the max column length
CompanyId
- You can provide your own column name for this column
- The CompanyId column persists the identification of the company of the connected user if any
- This column should be nullable
- This column should be of type character varying
- The logger will truncate any info exceding the max column length
SeverityCode
- You can provide your own column name for this column
- The SeverityCode column persists the SeverityEnum code
- This column should be non nullable
- This column should be of type characater (one char is enough)
// Exemple of Sevirity enum and corresponding codes
// ------------------------------------------------
public enum SeverityEnum
{
Ok, // "O"
Debug, // "D"
Info, // "I"
Warning, // "W"
Error, // "E"
Fatal, // "F"
}
MachineName
This column is certainly usefull in web farms
- You can provide your own column name for this column
- The MachineName column persists Environment.MachineName
- This column should be non nullable
- This column should be of type character varying
- The logger will truncate any info exceding the max column length
Topic
This column lets you group logs for a given topic
- You can provide your own column name for this column
- This column should be nullable
- This column should be of type character varying
- The logger will truncate any info exceding the max column length
Context
Where does it happened
- You can provide your own column name for this column
- The Context column persists method name, filepath and code line number
- This column should be non nullable
- This column should be of type character varying
- The logger will truncate any info exceding the max column length
Message
What happened
- You can provide your own column name for this column
- The Message column persists the message info
- This column should be non nullable.
- This column should be of type text
CreateDateUtc
When does it happened
- You can provide your own column name for this column
- The Message column persists the UTC date.
- This column should be non nullable.
- This column should be of type timestamp with time zone
Usage
using PvWay.LoggerService.PgSqlLogWriter.nc6;
Console.WriteLine("Hello, PostgreSQL LoggerService");
Console.WriteLine("-------------------------------");
Console.WriteLine();
const string pgSqlCs = "Server=localhost;" +
"Database=postgres;" +
"User Id=sa;" +
"Password=S0mePwd_;";
var pgSqlLogger = PgSqlLogWriter.FactorLoggerService(
async () =>
await Task.FromResult(pgSqlCs));
Console.WriteLine("logging using PostgreSQL");
await msSqlLogger.LogAsync("some debug");
Console.WriteLine("done");
Happy coding
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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. |
-
net6.0
- Npgsql (>= 7.0.7)
- PvWay.LoggerService.nc6 (>= 2.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Upgrade NpgSql nuGet from 7.0.4 to 7.0.7