Console Logging
With the approach to driving the display figured out, I thought I’d begin some of the PC-side software. I wrote way back when that it would save some toil if I could write a util to automatically generate the front-panel word layout, so that’s a good place to start.
That led me down a side path that’s worth documenting. It’s always nice to decouple dependencies if you can, and I’d rather not have direct calls to print to the console scattered all over the code; it makes things difficult if we later want to plug in a more sophisticated logging pipeline.
In .NET, ILogger is a common interface that provides integration with several different logging sinks and offers API’s for tracking execution spans and the like. It has built-in sinks to output data to the console in a few different formats, but they add decoration, color, and line-splitting to your output. The default console logging module yields output like this:
The “info” string represents the log level, one of {critical, error, warning, information, debug, trace}
. Program
is the name of the class instantiating the logger object.
This isn’t bad, necessarily, but it’s very chatty. There’s config so you can remove the line break, but the default classes don’t let you trim off all the decoration and get true printf-style behavior.
.NET 5 allows for the implmentation of custom console log formatting. I found it touchy to get just right, but this reference sample from Microsoft’s Maryam Ariyan got me where I wanted to go.
The result is all the API and pluggability benefits of ILogger with the simplicity of basic console output:
I’ll use the resulting logging library for the PC-side software on this project.