saleem-mirza / serilog-sinks-sqlite

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

How to use custom columns in Serilog.Sinks.SQLite #30

Closed AtlantisDe closed 4 years ago

AtlantisDe commented 4 years ago

Description

How to use custom columns in Serilog.Sinks.SQLite

default

CREATE TABLE Logs (
    id              INTEGER      PRIMARY KEY AUTOINCREMENT,
    Timestamp       TEXT,
    Level           VARCHAR (10),
    Exception       TEXT,
    RenderedMessage TEXT,
    Properties      TEXT
);

i need like Entity insert

Logger.Information(  new UserItem {  Name="customer",Age=99999} );
CREATE TABLE LogsEntityDemo  (
    id              INTEGER      PRIMARY KEY AUTOINCREMENT,
    Name           VARCHAR (10),
    Age  INT,
);
        /// <summary>UserItem</summary>
        public class UserItem
        {
            /// <summary>Name</summary>
            public string Name { get; set; }
            /// <summary>Age</summary>
            public int Age { get; set; }
        }

pls help me

tks very much
Davidos533 commented 2 years ago

Hello, it's simple Tiny extension library - Serilog.Sinks.SQLite just not support custom db table My solution just dowload library, and rewrite app parts for you purposes

I hust download Serilog.Sinks.SQLite from: https://github.com/saleem-mirza/serilog-sinks-sqlite -next i extract project files -create new C# net core 3.1 classes library project in my solution -put in my new project downloaded Serilog.Sinks.SQLite .cs files -dowload required nu get packeges

My library project config:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
    <PackageReference Include="Serilog" Version="2.11.0" />
    <PackageReference Include="System.Data.SQLite" Version="1.0.115.5" />
  </ItemGroup>

</Project>

image