It’s easy to overlook how small differences in logging syntax can affect performance, log structure, and searchability.

Take this innocent-looking log:

C#
logger.LogInformation("Hello " + name);

Now compare it to:

C#
logger.LogInformation($"Hello {name}");

And finally, this one:

C#
logger.LogInformation("Hello {Name}", name);

They all seem to do the same thing, right?

Well… not quite. Let’s dive into what really sets them apart and why you should care.

1. Logging with String Concatenation

This method involves building log messages by explicitly joining strings and variable values using concatenation operators.

C#
string user = "Alice";
int id = 123;
logger.LogInformation("User " + user + " with ID " + id + " logged in.");

Drawbacks

2. Logging with String Interpolation

String interpolation provides a more concise and readable syntax for embedding expressions.

C#
string user = "Bob";
int id = 456;
logger.LogInformation($"User {user} with ID {id} logged in.");

Drawbacks: while more readable than concatenation,

3. Structured Logging

Structured logging involves emitting log data in a predefined, machine-readable format like JSON or key-value pairs, rather than plain text.

It separates the log message template from the dynamic data, allowing for richer querying and analysis. example.

C#
string user = "Charlie";
int id = 789;
logger.LogInformation("User {UserName} with ID {UserId} logged in.", user, id);

Advantages

Benchmarking results

Benchmarking result

Modern .NET logging is more than just writing strings to the console. If you’re using tools like Seq, structured logging unlocks their full power, with better filtering, alerting, and dashboards.

So the next time you’re tempted to log like this:

C#
logger.LogInformation("User logged in: " + userId);

…try this instead:

C#
logger.LogInformation("User logged in: {UserId}", userId);

Your future self and your DevOps team will thank you.