log4mongo/log4mongo-net

ERROR [MongoDBAppender] - Value cannot be null

mwcoope opened this issue · 3 comments

So I have multiple projects deployed to a single server using log4mongo and all with seemingly the same configuration, but a couple applications are logging successfully while others are not. They are receiving the following error as output from the internal.debug setting for log4net:

log4net:ERROR [MongoDBAppender] ErrorCode: GenericFailure. Failed in DoAppend
System.ArgumentNullException: Value cannot be null.
Parameter name: value
   at MongoDB.Bson.BsonDocument.Add(String name, BsonValue value)
   at Log4Mongo.BackwardCompatibility.BuildBsonDocument(LoggingEvent loggingEvent)
   at Log4Mongo.MongoDBAppender.BuildBsonDocument(LoggingEvent log)
   at Log4Mongo.MongoDBAppender.Append(LoggingEvent loggingEvent)
   at log4net.Appender.AppenderSkeleton.DoAppend(LoggingEvent loggingEvent)

Web.config

<configuration>
...
<log4net>
    <appender name="MongoDBAppender" type="Log4Mongo.MongoDBAppender, Log4Mongo">
      <connectionStringName value="MongoConnectionString" />
      <collectionName value="logs" />
    </appender>
    <root>
      <level value="ALL" />
      <appender-ref ref="MongoDBAppender" />
    </root>
  </log4net>
...
</configuration>

Where MongoConnectionString is a valid connectionsting. Using the standard document logging, it appears that some field it is trying to access is missing a value, and therefore failing.

When I debug my project locally, the logs are written successfully.

Am I missing something here? How can I know what value is null/missing? What standard document fields could be the issue here?

gimmi commented

Hi @mwcoope

The configuration seems fine, maybe something with a different version of MongoDB driver?

Hey @gimmi

Thank you for your reply. I can't remember exactly how I had this resolved, but I think you are correct. IIRC, one of the nuget packages I was using had a dependency on a different version of MongoDB driver and was building using an earlier version than specified in my project. Not all my projects needed this library, which would explain why some had the issue but others did not.