You Don't Monitor Your Sitecore Instance Close Enough
Learn why and how to effectively monitor the log output of your Sitecore solution during development.
Running a healthy Sitecore Experience Platform in production starts on your developer machine.
Coming up with a consistent and useful logging strategy on a Sitecore solution is not trivial. Especially if you're kicking off a new project, make sure you have discussed what to log and what not and how to format your log output. Make sure you have a common understanding of the semantics behind the log levels - yes, there's a DEBUG level, too! ;-)
While we hopefully all agree that logging is vital to any Sitecore solution, I'd like to introduce you to tools that allow you to leverage the work you put into writing these log statements.
This article is not about monitoring logs on your production or integration server. That's where tools like Splunk or Log Analytics (Azure) come into play.
Monitoring the log output of your local Sitecore instance is a good thing:
- You test your logging constantly and assure the output is what you'd like to get back from production in case of issues.
- You can address otherwise overlooked issues early (we're customizing a platform after all).
- You increase the overall healthiness of the solution up to production (you don't push with build warnings either, do you?).
That said, one would assume running a log viewer during development is a common thing. But at least that's not the case amongst people answering my Twitter poll:
Yes, the poll has no statistical relevance, it's a first impression at best. But that first impression shows: the most are reading logs in their text editor. This involves opening log files, scrolling through meaningless lines, finding the relevant entry and making sure the file is refreshed when you use it the next time.
I think we can do better.
Log Viewer Setup in 5 Minutes
There are only two steps from zero to hero:
Sitecore log files are not ideal for constant log stream reading, luckily log4net comes with a UDP Appender to stream the log output directly to the UDP receivers of the two tools. And setup is as easy as creating a new config file in the include directory of your local Sitecore instance, containing the configuration patch below.
This configuration registers all default loggers plus the logger for the nowadays must-have Sitecore Powershell Extension (SPE). No more logfile switching to debug your Solr query or validating the crawler results!
Log Viewers to Pick
Let's look at two tools that are equally easy to set up:
- Log2Console (open source, BSD license)
- Log4View (closed source, proprietary license)
Here's a preview of both running side by side. Log4View on the left, Log2Console on the right against a running Sitecore 9.1 instance with the log level set to DEBUG.
Still with me? Good. Here's a quick walk through on the setup and basics of the two tools.
You can download Log2Console from the Github Releases page (unzip the source, you'll find the installer in the ./output directory) or, if Chocolatey is a thing for you, run "choco install log2console" in your console.
Installation and setup are straight forward. After installation, go to the "Receivers" and add a UDP receiver with defaults as shown below:
Features, Highs and Lows
Log2Console focuses on the basics. Quick filtering according to the log level and a free text filter can be applied to the log stream. Additional filtering around the dynamically built loggers can also be handy to focus on specific areas.
One of my absolute favorites about Log2Console is the animated taskbar icon that lights up when new log messages are received.
That said, Log2Console has its issues. It seems to be an abandoned project; no active development is happening. Filtering with the text search results in an unresponsive UI if you try to search on a larger stream/set of messages. You can pause the stream before you search and then start streaming again, it's just two more clicks, but the tool would really benefit from a bugfix or two.
A 30-day trial version with all the pro features is available for download. After that period Log4View will still run under the community edition with less features if you comply with the license terms.
Setup is almost as easy as with Log2Console: Go to the "Start"-Tab and add a "Network Receiver" from the ribbon. Select UDP and make sure the port matches your configuration for the Sitecore instance.
Features, Highs and Lows
While I haven't spent as much time with Log4View as I have with Log2Console, it offers a plethora of options. An important one is the notification threshold for log levels. WARNING or ERROR are good choices for Sitecore.
Even with heavy streaming and filtering resources used by the two viewers are not relevant if you're running a modestly performing developer device. The quick tests on my Lenovo X1 Extreme, i7-8850H @ 2.6Ghz with 64GB RAM revealed the following average resource usage with a Sitecore 9.1 XP Standalone installation in DEBUG mode:
|RAM used||~15mb to ~200mb||~185mb to ~500mb|
Conclusion & Recommendation
Log4View comes with a GPU accelerated UI thanks to a newer .Net Framework version and overall feels more stable but also a bit heavier. That said, if you're coming from the text editor, it's pretty safe to get your feet wet with Log2Console. If you already know Log2Console and need more options to sort, filter and colorize the output, give Log4View a try. It sure offers all the options and stability Log2Console doesn't.
The Blind Side
Of course, this is not the end of the story. There's plenty of room for improvements. Issues with this approach:
Newer services like the xConnect API and the .Net Core based services from Sitecore (xConnect Jobs, Identity Server, Publishing Service, Universal Tracker etc.) are not covered by this solution. These services do not use a log4net implementation but support structured logging and thus allow for an even more powerful log monitoring out of the box.
I'll follow up on how we can cover our blind side in a later post. Stay tuned, subscribe or follow us on Twitter to not miss upcoming publications.
Update Jan. 2020: Sitecore Climber wrote an article on how to enable the UDP output for Sitecore Commerce and one on how to enable the UDP output for xConnect.
Credits: Thanks to Pascal Mathys for mentioning Log4View in the poll and all others for voting.