Configuration Presets
Pre-configured formatter option sets for common deployment scenarios. Choose a configuration profile to quickly set up EasyMessages for your environment without manually setting every option.
Available Presets
EasyMessages formatter behavior can be configured per environment:
| Environment | Use Case | Output | Performance |
|---|---|---|---|
| Development | Local dev | Verbose | Low priority |
| Production | Live systems | Minimal | Optimized |
| Staging | Pre-production | Balanced | Balanced |
| Testing | Test runners | Essential only | Fast |
Using Environment-Based Configuration
Auto-Select by Environment
Program.cs:
using RecurPixel.EasyMessages.Configuration;
var builder = WebApplication.CreateBuilder(args);
// Configure formatter based on environment
if (builder.Environment.IsDevelopment())
{
FormatterConfiguration.Configure(options =>
{
options.IncludeTimestamp = true;
options.IncludeMetadata = true;
options.IncludeNullFields = true;
});
}
else if (builder.Environment.IsProduction())
{
FormatterConfiguration.Configure(options =>
{
options.IncludeTimestamp = false;
options.IncludeMetadata = false;
options.IncludeNullFields = false;
});
}
var app = builder.Build();
app.Run();
Via appsettings.json
Load formatter configuration from appsettings files and apply at startup:
appsettings.Development.json:
{
"EasyMessages": {
"Formatter": {
"IncludeTimestamp": true,
"IncludeMetadata": true,
"IncludeNullFields": true
}
}
}
appsettings.Production.json:
{
"EasyMessages": {
"Formatter": {
"IncludeTimestamp": false,
"IncludeMetadata": false,
"IncludeNullFields": false
}
}
}
Program.cs:
using RecurPixel.EasyMessages.Configuration;
var builder = WebApplication.CreateBuilder(args);
// Load from appsettings section
var fmtSection = builder.Configuration.GetSection("EasyMessages:Formatter");
FormatterConfiguration.Configure(options =>
{
options.IncludeTimestamp = fmtSection.GetValue("IncludeTimestamp", true);
options.IncludeMetadata = fmtSection.GetValue("IncludeMetadata", true);
options.IncludeNullFields = fmtSection.GetValue("IncludeNullFields", false);
});
var app = builder.Build();
app.Run();
Development Configuration
Optimized for: Local development and debugging
Settings
FormatterConfiguration.Configure(options =>
{
options.IncludeTimestamp = true;
options.IncludeCorrelationId = true;
options.IncludeHttpStatusCode = true;
options.IncludeMetadata = true;
options.IncludeData = true;
options.IncludeHint = true;
options.IncludeNullFields = true; // Include all fields even if null
});
Characteristics
| Feature | Value | Reason |
|---|---|---|
| Timestamp | [✓] Included | Know exactly when things happened |
| Correlation ID | [✓] Included | Track requests |
| HTTP Status | [✓] Included | See mapped status codes |
| Metadata | [✓] Included | Full diagnostic context |
| Null Fields | [✓] Included | See all fields, even empty |
Sample Output
{
"success": true,
"code": "CRUD_001",
"type": "success",
"title": "User Created",
"description": "User has been created successfully.",
"data": {
"id": 123,
"name": "John Doe",
"email": "john@example.com"
},
"timestamp": "2026-01-09T14:30:00.000Z",
"httpStatusCode": 200,
"hint": null,
"parameters": {},
"metadata": {
"source": "WebAPI"
}
}
When to Use
[✓] Use for:
- Local development
- Debugging issues
- Understanding message flow
- Learning the library
[ ] Don’t use for:
- Production (too verbose)
- Performance testing
Production Configuration
Optimized for: Live production systems
Settings
FormatterConfiguration.Configure(options =>
{
options.IncludeTimestamp = false;
options.IncludeCorrelationId = true;
options.IncludeHttpStatusCode = false;
options.IncludeMetadata = false;
options.IncludeData = true;
options.IncludeHint = false;
options.IncludeNullFields = false; // Smaller responses
});
Characteristics
| Feature | Value | Reason |
|---|---|---|
| Timestamp | [ ] Not included | Reduce payload size |
| Correlation ID | [✓] Included | Distributed tracing |
| HTTP Status | [ ] Not included | Reduce payload |
| Metadata | [ ] Not included | Privacy-safe, reduce payload |
| Null Fields | [ ] Not included | Smaller JSON |
Sample Output
{
"success": true,
"code": "CRUD_001",
"type": "success",
"title": "User Created",
"description": "User has been created successfully.",
"data": {
"id": 123,
"name": "John Doe"
},
"correlationId": "0HMVQK8F3J8QK:00000001"
}
When to Use
[✓] Use for:
- Production deployments
- Privacy-sensitive applications
- GDPR/CCPA compliance
- High-traffic systems
[ ] Don’t use for:
- Development (too minimal for debugging)
Benefits
- [✓] Privacy-safe: No PII (Personal Identifiable Information)
- [✓] Performance: Minimal payload, smaller JSON
- [✓] Compliance: GDPR/CCPA friendly
Staging Configuration
Optimized for: Pre-production QA and testing
Settings
FormatterConfiguration.Configure(options =>
{
options.IncludeTimestamp = true;
options.IncludeCorrelationId = true;
options.IncludeHttpStatusCode = true;
options.IncludeMetadata = true;
options.IncludeData = true;
options.IncludeHint = true;
options.IncludeNullFields = false;
});
Sample Output
{
"success": true,
"code": "CRUD_001",
"type": "success",
"title": "User Created",
"description": "User has been created successfully.",
"data": {
"id": 123,
"name": "John Doe"
},
"timestamp": "2026-01-09T14:30:00.000Z",
"correlationId": "0HMVQK8F3J8QK:00000001",
"httpStatusCode": 200
}
When to Use
[✓] Use for:
- Staging environment
- QA testing
- Pre-production validation
- UAT (User Acceptance Testing)
Testing Configuration
Optimized for: Unit and integration tests
Settings
FormatterConfiguration.Configure(options =>
{
options.IncludeTimestamp = false; // Deterministic output
options.IncludeCorrelationId = false; // No dynamic IDs
options.IncludeHttpStatusCode = false;
options.IncludeMetadata = false;
options.IncludeData = true;
options.IncludeHint = false;
options.IncludeNullFields = false;
});
Characteristics
| Feature | Value | Reason |
|---|---|---|
| Timestamp | [ ] Not included | Deterministic test assertions |
| Correlation ID | [ ] Not included | Deterministic tests |
| Metadata | [ ] Not included | Predictable output |
Sample Output
{
"success": true,
"code": "CRUD_001",
"type": "success",
"title": "User Created",
"description": "User has been created successfully.",
"data": {
"id": 123,
"name": "John Doe"
}
}
Example Test
[Fact]
public void Create_User_Returns_Success_Message()
{
// Arrange - configure deterministic output for tests
FormatterConfiguration.Configure(options =>
{
options.IncludeTimestamp = false;
options.IncludeCorrelationId = false;
options.IncludeNullFields = false;
});
var message = Msg.Crud.Created("User")
.WithData(new { Id = 123, Name = "John Doe" });
// Act
var json = message.ToJson();
// Assert (deterministic - no timestamp or correlation ID)
Assert.Contains("\"code\": \"CRUD_001\"", json);
Assert.Contains("\"success\": true", json);
Assert.DoesNotContain("timestamp", json);
}
Preset Comparison
Feature Matrix
| Feature | Development | Production | Staging | Testing |
|---|---|---|---|---|
| Code | [✓] | [✓] | [✓] | [✓] |
| Type | [✓] | [✓] | [✓] | [✓] |
| Title | [✓] | [✓] | [✓] | [✓] |
| Description | [✓] | [✓] | [✓] | [✓] |
| Data | [✓] | [✓] | [✓] | [✓] |
| Timestamp | [✓] | [ ] | [✓] | [ ] |
| CorrelationId | [✓] | [✓] | [✓] | [ ] |
| HttpStatusCode | [✓] | [ ] | [✓] | [ ] |
| Hint | [✓] | [ ] | [✓] | [ ] |
| Metadata | [✓] | [ ] | [✓] | [ ] |
| Null Fields | [✓] | [ ] | [ ] | [ ] |
Choosing the Right Configuration
Decision Tree
Are you running tests?
├─ Yes → Testing configuration (no timestamps, no correlation IDs)
└─ No
│
What environment?
├─ Local development → Development configuration (everything on)
├─ Staging/QA → Staging configuration (balanced)
└─ Production → Production configuration (minimal, privacy-safe)
By Use Case
| Use Case | Recommended | Reason |
|---|---|---|
| Local development | Development | Maximum debugging info |
| Unit tests | Testing | Deterministic output |
| Integration tests | Testing | Predictable, fast |
| QA/Staging environment | Staging | Balanced diagnostics |
| Production deployment | Production | Privacy-safe, optimized |
| Load testing | Production | Production-like performance |
Best Practices
[✓] DO:
- Match configuration to environment
if (env.IsDevelopment()) FormatterConfiguration.Configure(o => o.IncludeNullFields = true); else FormatterConfiguration.Configure(o => o.IncludeNullFields = false); - Configure at startup before any messages
// Configure in Program.cs before app starts serving requests FormatterConfiguration.Configure(options => { ... }); - Use deterministic output for tests - Disable timestamps and correlation IDs
[ ] DON’T:
- Don’t use verbose output in production - Privacy and performance issues
- Don’t expose null fields in production - Larger responses, potential info leak
- Don’t include timestamps in test assertions - Makes tests non-deterministic
Next Steps
- Setup and Configuration - Complete setup guide
- API Response Patterns - REST API response patterns
- Logging Integration - Advanced logging strategies
Questions? Ask in Discussions