数据未进入日志 Table

Data in not going inside Log Table

我正在使用 Serilog.Sinks.PostgresqlNuget 包在 PostgreSQL 中写入 lon 但它没有写入任何日志

IDictionary<string, ColumnWriterBase> columnWriters = new Dictionary<string, ColumnWriterBase>
{
  {"message", new RenderedMessageColumnWriter()},
  {"message_template", new MessageTemplateColumnWriter() },
  {"level", new LevelColumnWriter(true, NpgsqlDbType.Varchar) },
  {"raise_date", new TimeStampColumnWriter() },
  {"exception", new ExceptionColumnWriter() },
  {"properties", new LogEventSerializedColumnWriter() },
  {"props_test", new PropertiesColumnWriter(NpgsqlDbType.Text) },
  {"machine_name", new SinglePropertyColumnWriter("MachineName", PropertyWriteMethod.Raw) }
};

此代码不应写入任何日志数据。此代码是启动和注册记录器的一部分。

string connectionstring = "User 
ID=serilog;Password=serilog;Host=localhost;Port=5432;Database=logs";

string tableName = "logs";

//Used columns (Key is a column name)
IDictionary<string, ColumnWriterBase> columnWriters = new Dictionary<string, ColumnWriterBase>
{
    {"message", new RenderedMessageColumnWriter() },
    {"message_template", new MessageTemplateColumnWriter() },
    {"level", new LevelColumnWriter(true, NpgsqlDbType.Varchar) },
    {"raise_date", new TimeStampColumnWriter() },
    {"exception", new ExceptionColumnWriter() },
    {"properties", new LogEventSerializedColumnWriter() },
    {"props_test", new PropertiesColumnWriter(NpgsqlDbType.Text) },
    {"machine_name", new SinglePropertyColumnWriter("MachineName", PropertyWriteMethod.Raw) }
};

var logger = new LoggerConfiguration()
                    .WriteTo.PostgreSQL(connectionstring, tableName, columnWriters)
                    .CreateLogger();

然后你可以写一个像这样的日志:

logger.ForContext("Context", "test")
                .Warning("THIS IS A WARN");

很高兴地说我喜欢这个问题 这是因为我在 table 中添加了额外的列(Id 自动递增) https://www.symbolsource.org/Public/Metadata/NuGet/Project/Npgsql/3.0.0-beta0001/Release/.NETFramework,Version%3Dv4.5/Npgsql/Npgsql/NpgsqlBinaryImporter.cs?ImageName=Npgsql 现在它对我来说工作正常