Skip to main content

Posts

Featured

Testing Serilog Logging with MEL and TestCorrelator

 Logging as a cross-cutting concern might be implemented in one of plenty of ways. Recently I ran into an attribute-based implementation using passive attributes . What happened was at certain points in the attributed object's lifecycle it had to write messages to a logger. As the author did not want to cramp logging into the production code, they decided to use a passive attribute and a filter checking for said attribute to take care of logging. However, the filter was not tested, lowering our test coverage. What I had to do was injecting a mocked Microsoft.ExtensibilityLogging.ILogger<T> into the filter. Easy, right? Well, sort of. The project uses Serilog for logging. Serilog does support testing through the rather useful TestCorrelator Sink . The canonical way of creating a TestCorrelator is as follows: Serilog.ILogger logger = new LoggerConfiguration().WriteTo.TestCorrelator().CreateLogger(); Looks good, except for the tiny issue that my LoggingFilter expects a paramet...

Latest Posts

Excluding Generated Code from Azure DevOps Code Coverage

Methodology Bits: Definition of Done

Methodology Bits: Definition of Ready

Methodology Bits: The Triad Meeting

Methodology Bits: The Daily Standup

A Legacy Code Retreat Session, part 2 - Heads up and Preparations

A Legacy Code Retreat Session, part 1 - Introduction

Export Visual Studio Installation Configuration

Structuring .net Framework Projects (bin and obj Folder Locations)