Use MongoDB to store Sitecore log entries centrally!

The idea is to store a copy of the Sitecore logs in a central location such as a common MongoDB. Why? hmm why not? If you are running multiple CD servers and you want to view the logs for all of them in one location, might be one reason. The reason will become apparent in the coming days/weeks!

Next, we need a class MongoLogger, implementing the AppenderSkeleton from the log4net implementation tucked away in Sitecore.Logging.dll. We will pass in the connection string name and the collection name from the config.

I also added a Logger which by default inherits the root. It’s generally not a good practice to add to the root node.

The MongoDBAppender logger is explicitly configured to log to MongoDBAppender, and is configured not to inherit settings from parent loggers (additivity=”false”). Therefore it doesn’t log to LogFileAppender. If you set additivity=”true” it will inherit settings and log to both LogFileAppender and MongoDBAppender.

Here we added the MongoDBAppender followed by LogFileAppender. What this does is that it duplicates the entries in to the MongoDB, which is exactly what I am looking for.

Related

This is a personal blog. Any views or opinions represented in this blog are my own and do not represent those of people, institutions or organizations that the I may or may not be associated with in professional or personal capacity including past, current and future employers, unless explicitly stated.