Labelling Entity Framework Core queries in log files using TagWith

In Entity Framework Core (2.2+) if you’re capturing queries in logs consider using the TagWith feature to output an arbitrary comment along with your queries. This can be helpful for identifying where in the code a particular query is executed from or to otherwise provide some context which will be helpful when scrolling through the logs.

Usage is simple, for example, the following query…

Entity Framework tags

will produce the following SQL…

Entity Framework tags

 

Leave a Reply

Your email address will not be published. Required fields are marked *