Closed wuzhenda closed 2 years ago
the serilog-sinks-mongodb version is 5.1.2;
the setting is
{ "Name": "MongoDBBson", "Args": { "databaseUrl": "mongodb://1.1.1.1", "collectionName": "logdebug", "cappedMaxSizeMb": "1024", "cappedMaxDocuments": "50" } }
" Timespan" type will cause the exception too.
so I changed the code from line 54 in the MongoDbDocumentHelpers.cs :
if (value is ScalarValue scalar)
{
if(scalar.Value is Uri)
{
return BsonValue.Create(scalar.Value.ToString());
}
if (scalar.Value is TimeSpan)
{
return BsonValue.Create(scalar.Value.ToString());
}
return BsonValue.Create(scalar.Value);
}
when we use DI to other 3rd lib,we don't know what they output to the log, so maybe there are other types will lead to the exceptions.
I think there maybe other type will cause the exception. and the exception stoped all the next logs.
maybe we should catch other exceptions or turn all the ScalarValue type to string then to BsonValue?
when I use masstransit with serilong-sinks-mongodb, the masstranist log the host info, then the exception happened.
I debug the source code and find out that the Bson convert with url make that exception happened.