You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// {"@t":"2020-10-29T19:05:56.4176816Z","@m":"Completed in 30ms...","@i":"51812baa","DurationMs":30,"SourceContext":"SomeNamespace.SomeService","Scope":["Transaction"]}
100
+
```
101
+
102
+
Ifyousimplywanttoadda"bag"ofadditionalpropertiestoyourlogevents, however, thisextensionmethodapproachcanbeoverlyverbose. Forexample, toadd `TransactionId` and `ResponseJson` propertiestoyourlogevents, youwouldhavetodosomethinglikethefollowing:
103
+
104
+
```cs
105
+
// WRONG! Prefer the dictionary approach below instead
106
+
using (_logger.BeginScope("TransactionId: {TransactionId}, ResponseJson: {ResponseJson}", 12345, jsonString)) {
107
+
_logger.LogInformation("Completed in {DurationMs}ms...", 30);
Notonlydoesthisaddtheunnecessary `Scope` propertytoyourevent, butitalsoduplicatesserializedvaluesbetween `Scope` andtheintendedproperties, asyoucanseeherewith `ResponseJson`. Ifthiswere"real"JSONlikeanAPIresponse, thenapotentiallyverylargeblockoftextwouldbeduplicatedwithinyourlogevent!Moreover, thetemplatestringwithin `BeginScope` isratherarbitrary when all you want to do is add a bag of properties, and you start mixing enriching concerns with formatting concerns.
0 commit comments