A Visual Studio 2022 extension that provides syntax highlighting, brace matching, and navigation features for Serilog message templates and Serilog.Expressions in C#/.NET projects.
- Property names highlighted in theme-appropriate blue:
{UserId},{UserName} - Destructuring operator
@highlighted in warm orange/red:{@User} - Stringification operator
$highlighted in warm orange/red:{$Settings} - Format specifiers highlighted in green:
{Timestamp:yyyy-MM-dd} - Alignment highlighted in red:
{Name,10},{Price,-8} - Positional parameters highlighted in purple:
{0},{1} - Property braces highlighted for structure
- Multi-line verbatim strings fully supported with proper highlighting across lines
- C# 11 raw string literals supported with
"""delimiters for complex templates - Automatic theme adaptation - All colors automatically adjust for Light/Dark themes
- Filter expressions in
Filter.ByExcluding()andFilter.ByIncludingOnly() - Expression templates with control flow directives
- Operators highlighted in red:
and,or,not,like,in,is null - Functions highlighted in purple:
StartsWith(),Contains(),Length(), etc. - Keywords highlighted in blue: conditional and control flow keywords
- Literals highlighted in cyan/teal: strings, numbers, booleans, null
- Directives highlighted in magenta:
{#if},{#each},{#else},{#end} - Built-in properties highlighted in teal:
@t,@m,@l,@x,@i,@p - Theme-aware colors - All expression elements adapt to Light/Dark themes
- Works with any logger variable name (not just
_loggerorlog) - Supports both direct Serilog calls:
Log.Information(...) - Supports Microsoft.Extensions.Logging integration:
_logger.LogInformation(...) - Supports
BeginScopefor scoped logging:logger.BeginScope("Operation={Id}", operationId) - Supports
LogErrorwith exception parameter:logger.LogError(ex, "Error: {Message}", msg) - Recognizes configuration templates:
outputTemplate: "[{Timestamp:HH:mm:ss}...]"
- Immediate visual feedback as you type
- Highlighting appears as soon as you close braces
}(doesn't wait for closing quotes) - Supports incomplete strings during editing
- Light bulb suggestions when hovering over template properties
- Navigate to argument - jump from template properties to their corresponding arguments
- Click the light bulb and select "Navigate to 'PropertyName' argument"
- Interactive highlighting of property-argument connections
- When cursor is on a template property (e.g.,
{UserId}), both the property and its corresponding argument are highlighted - When cursor is on an argument, both the argument and its template property are highlighted
- Works across all string literal types (regular, verbatim
@"...", raw"""...""") - Supports complex scenarios including multi-line templates, collection expressions, and LogError with exception parameters
- Highlight matching braces when cursor is positioned on
{or} - Visual indication of brace pairs in complex templates
- Multi-line support - matches braces across line boundaries in verbatim and raw strings
- Press ESC to temporarily dismiss highlights
- Helps identify mismatched or nested braces
- Install directly from the Visual Studio Marketplace
- Or from within Visual Studio 2022:
- Go to Extensions > Manage Extensions
- Search for "Serilog Syntax Highlighting"
- Click Download and restart Visual Studio
- Download the latest
.vsixfile from the releases page - Double-click the
.vsixfile to install in Visual Studio 2022 - Restart Visual Studio
The extension automatically adapts to your Visual Studio theme with WCAG AA compliant colors:
- Automatic theme detection - Colors change instantly when switching between Light and Dark themes
- WCAG AA accessibility - All colors maintain 4.5:1+ contrast ratios for excellent readability
- Semantic color grouping - Related elements use harmonious color families:
- Properties: Blue family (
{UserId},{Name}) - Operators: Warm colors (
@,$) - Format specifiers: Green family (
:yyyy-MM-dd) - Expression functions: Purple family (
StartsWith(),Length())
- Properties: Blue family (
You can still customize colors to match your preferences:
- Go to Tools > Options > Environment > Fonts and Colors
- In the Display items list, look for:
- Serilog Property Name
- Serilog Destructure Operator (@)
- Serilog Stringify Operator ($)
- Serilog Format Specifier
- Serilog Alignment
- Serilog Positional Index
- Serilog Property Brace
- Serilog Expression Property
- Serilog Expression Function
- Serilog Expression Keyword
- Serilog Expression Literal
- Serilog Expression Operator
- Serilog Expression Directive
- Serilog Expression Built-in
- Select any item and modify its Item foreground color
- Click OK to apply changes
Note: Custom colors override the automatic theme-aware colors.
After installation, the extension works automatically - no configuration required!
- Open any C# file that uses Serilog logging
- Start typing a Serilog log statement:
_logger.LogInformation("User {UserId} logged in", userId);
- See instant highlighting as you type - properties turn blue, operators yellow, etc.
- Try navigation: Hover over a property like
{UserId}and click the light bulb to jump to its argument - Test brace matching: Place your cursor on any
{or}to see its matching pair highlighted
Create a new C# file and paste this to see all features:
using Serilog;
Log.Information("User {UserId} logged in with {@Details} at {Timestamp:HH:mm:ss}",
userId, userDetails, DateTime.Now);You should see:
UserIdin blue (adapts to your theme)@in warm orange/red,Detailsin blueTimestampin blue,:HH:mm:ssin green- Matching braces highlighted when cursor is on them
- Colors automatically match your Light/Dark theme preference
The extension recognizes and highlights all Serilog message template features:
// Basic properties
logger.LogInformation("User {UserId} logged in at {LoginTime}", userId, loginTime);
// Destructuring (captures object structure)
logger.LogInformation("Processing user {@User}", user);
// Stringification (forces string representation)
logger.LogInformation("Configuration loaded {$Settings}", settings);
// Format specifiers
logger.LogInformation("Current time: {Timestamp:yyyy-MM-dd HH:mm:ss}", DateTime.Now);
// Alignment
logger.LogInformation("Item: {Name,10} | Price: {Price,8:C}", name, price);
// Positional parameters (legacy support)
logger.LogWarning("Error {0} occurred in {1}", errorCode, methodName);
// Multi-line verbatim strings
logger.LogInformation(@"Processing report:
User: {UserName}
Department: {Department}
Generated: {Timestamp:yyyy-MM-dd}", userName, dept, DateTime.Now);
// C# 11 raw string literals (no escaping needed for quotes)
logger.LogInformation("""
Processing record:
ID: {RecordId}
Status: {Status}
User: {@User}
""", recordId, status, user);
// Configuration templates
Log.Logger = new LoggerConfiguration()
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}")
.CreateLogger();
// Serilog.Expressions filter syntax
Log.Logger = new LoggerConfiguration()
.Filter.ByExcluding("RequestPath like '/health%'")
.Filter.ByIncludingOnly("Level = 'Error' or StatusCode >= 500")
.CreateLogger();
// Expression templates with control flow
var expressionTemplate = new ExpressionTemplate(
"{#if Level = 'Error'}β{#else}β
{#end} {@m}");
// Computed properties with expressions
.Enrich.WithComputed("ResponseTime", "EndsWith(RequestPath, '.json') ? Elapsed * 2 : Elapsed")The solution includes a complete example project (Example/) that demonstrates all syntax highlighting features:
cd Example
dotnet runOpen Example/Program.cs in Visual Studio to see the extension in action with comprehensive examples of every supported syntax feature.
The extension automatically detects Serilog calls regardless of how you name your logger variables:
// All of these work automatically
_logger.LogInformation("Message with {Property}", value);
logger.LogDebug("Debug message with {Data}", data);
myCustomLogger.LogWarning("Warning with {Details}", details);
log.LogError("Error with {Context}", context);- Visual Studio 2022 (17.0 or later)
- Visual Studio SDK
- .NET Framework 4.7.2
# Build the extension
.\build.ps1
# Run tests
.\test.ps1
# The built .vsix file will be in SerilogSyntax\bin\Debug\The extension uses Visual Studio's extensibility APIs:
- Roslyn Classification API - For syntax highlighting via
IClassifier - Roslyn Tagging API - For brace matching via
ITagger<TextMarkerTag> - Suggested Actions API - For navigation features via
ISuggestedActionsSourceProvider - MEF (Managed Extensibility Framework) - For Visual Studio integration
Key components:
SerilogClassifier- Handles syntax highlighting with smart cache invalidationSerilogBraceMatcher- Provides brace matchingSerilogNavigationProvider- Enables property-to-argument navigationPropertyArgumentHighlighter- Highlights property-argument connections on cursor positionSerilogCallDetector- Optimized Serilog call detection with pre-check optimizationSerilogThemeColors- Theme-aware color management with WCAG AA complianceTemplateParser- Parses Serilog message templatesLruCache- Thread-safe LRU cache providing 268x-510x performance improvement
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new features
- Run the test suite:
.\test.ps1 - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
