Serilog是.NET开源结构化日志类库
开源地址:https://github.com/serilog
官网:https://serilog.net/html
Serilog能作什么:git
想对Serilog多点了解,请查阅[译]Serilog Tutorial,翻译的很棒。程序员
在本身的项目中使用Serilog并使用MongoDB记录日志,须要nuget引用 Serilog
和 Serilog.Sinks.MongoDB
。
我引用的是 Serilog 2.7.1
和 Serilog.Sinks.MongoDB 3.1.0
Serilog.Sinks.MongoDB 3.1.0
依赖的是的MongoDB组件库是 MongoDB.Driver 2.3.0
、MongoDB.Driver.Core 2.3.0
、MongoDB.Bson 2.3.0
,因此当nuget引用Serilog.Sinks.MongoDB 3.1.0 天然会引用 MongoDB.Driver 2.3.0
、MongoDB.Driver.Core 2.3.0
、MongoDB.Bson 2.3.0
。
在记录MongoDB日志时报错,内容以下github
The GuidRepresentation for the reader is CSharpLegacy, which requires the binary sub type to be UuidLegacy, not UuidStandard
程序员google大法,找到一样的错误。点击查看:
The GuidRepresentation for the reader is CSharpLegacy, which requires the binary sub type to be UuidLegacy, not UuidStandardmongodb
文中给了三种解决方案:
一、修改全局配置 BsonDefaults.GuidRepresentation
ui
BsonDefaults.GuidRepresentation = GuidRepresentation.Standard;
二、当你建立collection时指定配置google
MongoDatabase db = ???; string collectionName = ???; var collectionSettings = new MongoCollectionSettings { GuidRepresentation = GuidRepresentation.Standard }; var collection = db.GetCollection<BsonDocument>(collectionName, collectionSettings);
三、更新驱动
原文以下.net
Solution 3.update to .NET Driver Version 2.5.x
.NET Driver Version 2.5.0 Release Notes say below:
The main new feature of 2.5.0 is support for the new features of the 3.6 version of the server:
...
Improved support for reading and writing UUIDs in BsonBinary subtype 4 format翻译
解决方案1和2都有点瞎啊,推测要改Serilog.Sinks.MongoDB的源码。天然先按照最简单的开始尝试,更新MongoDB驱动。日志
个人尝试解决方案:MongoDB.Driver 2.3.0
、MongoDB.Driver.Core 2.3.0
、MongoDB.Bson 2.3.0
通通更新至2.7.0版本(注:当前最新的稳定版本)。而后,嘣!问题解决!