Logger wrapper best practice

I used to use logging facades such as Common.Logging (even to hide my own CuttingEdge.Logging library), but nowadays I use the Dependency Injection pattern. This allows me to hide loggers behind an application-defined abstraction that adheres to both Dependency Inversion Principle and the Interface Segregation Principle (ISP) because it has one member and because the … Read more

Transactions in .net

There are 2 main kinds of transactions; connection transactions and ambient transactions. A connection transaction (such as SqlTransaction) is tied directly to the db connection (such as SqlConnection), which means that you have to keep passing the connection around – OK in some cases, but doesn’t allow “create/use/release” usage, and doesn’t allow cross-db work. An … Read more

Where to learn about VS debugger ‘magic names’

These are undocumented implementation details of the compiler, and subject to change at any time. (UPDATE: See GeneratedNames.cs in the C# sources for the current details; the description below is somewhat out-of-date.) However, since I’m a nice guy, here are some of those details: If you have an unused local variable that the optimizer removes, … Read more

JSON.Net throws StackOverflowException when using [JsonConvert()]

Json.NET does not have convenient support for converters that call JToken.FromObject to generate a “default” serialization and then modify the resulting JToken for output – precisely because the StackOverflowException due to recursive calls to JsonConverter.WriteJson() that you have observed will occur. One workaround is to temporarily disable the converter in recursive calls using a thread … Read more