- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经通过代码为 Serilog 尝试了 PostgreSQL 接收器,它的工作原理很吸引人。
这是工作代码:
static void Main(string[] args)
{
var connectionString = "Server=localhost; Port=5432; Database=subscriptions_log; User Id=postgres;Password=postgres";
string tableName = "errorlog";
IDictionary<string, ColumnWriterBase> columnWriters = new Dictionary<string, ColumnWriterBase>
{
{"message", new RenderedMessageColumnWriter(NpgsqlDbType.Text) },
{"level", new LevelColumnWriter(true, NpgsqlDbType.Varchar) },
{"raise_date", new TimestampColumnWriter(NpgsqlDbType.Timestamp) },
{"exception", new ExceptionColumnWriter(NpgsqlDbType.Text) }
};
using var log = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.PostgreSQL(connectionString, tableName, columnWriters)
.CreateLogger();
log.Information("Hello, Serilog!");
}
但是当我通过配置文件 serlig 使用它时,会在数据库中创建表,但由于未找到“Npgsql.NpgsqlBinaryImporter.Complete()”而没有插入任何行。
Exception while emitting periodic batch from Serilog.Sinks.PostgreSQL.PostgreSQLSink:
System.MissingMethodException:
Method not found: 'Void Npgsql.NpgsqlBinaryImporter.Complete()'.
at Serilog.Sinks.PostgreSQL.PostgreSQLSink.ProcessEventsByCopyCommand(IEnumerable`1 events, NpgsqlConnection connection)
at Serilog.Sinks.PostgreSQL.PostgreSQLSink.EmitBatch(IEnumerable`1 events)
at Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.EmitBatchAsync(IEnumerable`1 events)
at Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.OnTick()
项目文件
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Npgsql" Version="5.0.3" />
<PackageReference Include="Serilog" Version="2.10.1-dev-01285" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.2.0-dev-00264" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0-dev-00839" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0-dev-00909" />
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="2.3.0" />
<PackageReference Include="Serilog.Sinks.PostgreSQL" Version="2.2.0" />
<PackageReference Include="Serilog.Sinks.PostgreSQL.Configuration" Version="1.0.0" />
</ItemGroup>
</Project>
配置文件
{
"Serilog": {
"Using": [ "Serilog.Sinks.PostgreSQL.Configuration" ],
"MinimumLevel": "Debug",
"Enrich": [ "WithMachineName" ],
"WriteTo": [
{
"Name": "PostgreSQL",
"Args": {
"connectionString": "LogsDb",
"tableName": "errorlogs",
"needAutoCreateTable": true
}
}
]
},
"ConnectionStrings": {
"LogsDb": "Server=localhost; Port=5432; Database=subscriptions_log; User Id=postgres;Password=postgres"
},
"Columns": {
"message": "RenderedMessageColumnWriter",
"level": {
"Name": "LevelColumnWriter",
"Args": {
"renderAsText": true,
"dbType": "Varchar"
}
},
"raise_date": "TimestampColumnWriter",
"exception": "ExceptionColumnWriter"
}
}
以及调用方法:
static void Main(string[] args)
{
Serilog.Debugging.SelfLog.Enable(msg => Debug.WriteLine(msg));
Serilog.Debugging.SelfLog.Enable(Console.Error);
IConfiguration configuration = new ConfigurationBuilder()
.SetBasePath(Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..")))
.AddJsonFile("serilog.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.AddCommandLine(args)
.Build();
using var log = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
log.Error("Hello, Serilog!");
}
配置文件与描述完全一致
here .出于测试目的,我尝试了 .net 5.0 和 3.1,但没有成功。
最佳答案
您收到此错误的原因是 Serilog.Sinks.PostgreSQL取决于 Npgsql v4.0.2 ,但您强制将 Npgsql 升级到 v5.0.3它与最新版本的 Serilog.Sinks.PostgreSQL 不兼容(在撰写本文时 v2.2.0)。
<PackageReference Include="Npgsql" Version="5.0.3" />
NpgsqlBinaryImporter.Complete
is void
NpgsqlBinaryImporter.Complete
is ulong
MissingMethodException
因为... 4.x 中预期的方法在 5.x 中不再存在。
Npgsql
包引用并使用 v4.2.0,它将由 Serilog.Sinks.PostgreSQL 传递添加。或者,您可以将 Npgsql 升级到最新的 4.x 版本,即
v4.1.8在撰写本文时。
关于.net - 为什么 Serilog PostgreSQL 接收器不能通过配置工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66658664/
我正在寻找一种为 serilog 提供独立 XML/JSON 配置文件的方法,该文件是从应用程序本身运行的目录中动态加载的。 我正在寻找类似的东西 NLog provides .如 Nlog#Conf
我在我的 aspnet core 应用程序中使用 Serilog 进行日志记录。我需要频繁地将日志事件写入控制台(每秒 300-500 个事件)。我在 docker 容器内运行我的应用程序,并使用 O
是否可以创建一个自动为每条消息添加前缀的记录器? 我通常在每条消息前加上帐户前缀,因为这样更容易阅读,像这样: user1 - did something user2 - did another th
我具有动态更改日志文件路径的功能。但是,当我更改 Consul 中可配置的路径时,它会在两个地方(即旧路径和新路径)写入部分日志。更改日志文件路径应该可以在没有任何服务重启的情况下工作。我们如何存档?
我有很多这样的日志: Log.Information("Submitting order {@order}", order); 此日志通过 RabbitMq -> LogStash -> Elasti
我有很多这样的日志: Log.Information("Submitting order {@order}", order); 此日志通过 RabbitMq -> LogStash -> Elasti
我在服务器端使用 Serilog 为我所有的 .NETCore 服务使用控制台、文件和 Graylog 接收器。我也喜欢在我的 Windows 胖客户端(WPF 应用程序)中使用它。 与 后者我有问题
我正在使用 Serilog.Extensions.Logging 并使用此 outputTemplate 输出到控制台: "{Timestamp:HH:mm} [{Level:u3}] {Messag
Date时间的RollingFile Sink的当前输出如下 2015-04-06 18:40:54.400 +10:00 [Information] Hello World! 无论如何,有没有要消除
我使用 Serilog 作为 .NET 的库,它为文件、控制台和其他地方提供诊断日志记录。 我的问题是我在我的代码中声明了一些日志记录事件,但是在查看 Windows 事件查看器时,分配给我的日志的事
Serilog 的 Azure 表存储接收器是否可以像其他接收器(例如 Elasticsearch 和 Seq)一样通过 app/Web.config 配置,这些接收器可以从配置文件进行配置。 Azu
我正在使用 SeriLog 登录基于 IdentityServer3 的身份验证服务。我刚刚将 serilog.sinks.literate 插件替换为 serilog.sinks.file 插件,以
我使用 Serilog 作为 .NET 的库,它为文件、控制台和其他地方提供诊断日志记录。 我的问题是我在我的代码中声明了一些日志记录事件,但是在查看 Windows 事件查看器时,分配给我的日志的事
我正在尝试安装 serilog,但出现错误 PM> Install-Package Serilog Install-Package : 'Serilog' already has a dependen
从 nlog 转移到 serilog,我希望我的 .NET 框架桌面应用程序在每次运行时重用一个静态命名的日志文件,但在每个新进程中清除文件的内容。可以这样配置serilog吗? This is a
serilog 的可用接收器位于此处:https://github.com/serilog/serilog/wiki/Provided-Sinks 但不包括蔚蓝服务巴士。 目前是否正在努力创建一个?如
我要写 Serilog Warning .NET 集合中的事件,以便它们可以包含在给用户的报告中。我该怎么做 configure the static Log.Logger 写信给类似 static
我尝试在结构化模式下将 JSNLog 与 Serilog 一起使用,如文档中所述: http://jsnlog.com/Documentation/HowTo/StructuredLogging 我在
我正在从 log4net 切换到 Serilog,但错过了我在 log4net 中的一些格式化可能性。我没有找到关于我可以在 outputTemplate 中使用哪些格式化程序的任何文档。有什么方法可
我远不是具有任何 .net 经验的开发人员,但工作中的开发团队希望使用 Serilog 和 serilog-sinks-elasticsearch 将日志推送到我的 ELK 堆栈中。 查看 seril
我是一名优秀的程序员,十分优秀!