BrainEnterprise.Library.Logging
1.0.0
Prefix Reserved
dotnet add package BrainEnterprise.Library.Logging --version 1.0.0
NuGet\Install-Package BrainEnterprise.Library.Logging -Version 1.0.0
<PackageReference Include="BrainEnterprise.Library.Logging" Version="1.0.0" />
<PackageVersion Include="BrainEnterprise.Library.Logging" Version="1.0.0" />
<PackageReference Include="BrainEnterprise.Library.Logging" />
paket add BrainEnterprise.Library.Logging --version 1.0.0
#r "nuget: BrainEnterprise.Library.Logging, 1.0.0"
#:package BrainEnterprise.Library.Logging@1.0.0
#addin nuget:?package=BrainEnterprise.Library.Logging&version=1.0.0
#tool nuget:?package=BrainEnterprise.Library.Logging&version=1.0.0
BrainEnterprise.Library.Logging
A lightweight .NET performance tracking library with hierarchical correlation, async-safe context propagation, and structured logging via NLog. Designed for production monitoring and BI-ready analysis (e.g. Power BI).
Features
- Performance Tracking - Monitor execution duration with millisecond precision using
Stopwatch - Hierarchical Correlation - Automatic parent-child relationship tracking across nested operations
- Async-Safe Context - Correct context propagation in async/await and parallel scenarios via
AsyncLocal<T> - Slow Operation Detection - Configurable thresholds (global and per-operation) to flag slow executions
- Exception Tracking - Capture and log exceptions with full type and message details
- Zero-Overhead Disable - When disabled, returns an inactive singleton with virtually no performance cost
- Caller Info Capture - Automatic capture of caller method, file, and line number via compiler attributes
Target Frameworks
| Framework | Description |
|---|---|
netstandard2.0 |
.NET Core 2.0+, .NET 5+, .NET Framework 4.6.1+ |
net462 |
.NET Framework 4.6.2 |
net9 |
.NET 9 |
Dependencies
| Package | Version |
|---|---|
| NLog | 6.1.0 |
| System.Configuration.ConfigurationManager | 10.0.2 |
Getting Started
Configuration
The library can be configured via appSettings, appsettings.json, or environment variables.
| Key | Default | Description |
|---|---|---|
PerformanceTracker:LoggerName |
Performance.Execution |
NLog logger name |
PerformanceTracker:Enabled |
true |
Enable/disable all tracking |
PerformanceTracker:SlowThresholdMs |
3000 |
Default slow threshold (ms) |
App.config / Web.config:
<appSettings>
<add key="PerformanceTracker:LoggerName" value="Performance.Execution" />
<add key="PerformanceTracker:Enabled" value="true" />
<add key="PerformanceTracker:SlowThresholdMs" value="3000" />
</appSettings>
appsettings.json:
{
"PerformanceTracker": {
"LoggerName": "Performance.Execution",
"Enabled": true,
"SlowThresholdMs": 3000
}
}
Environment variables:
PerformanceTracker__LoggerName=Performance.Execution
PerformanceTracker__Enabled=true
PerformanceTracker__SlowThresholdMs=3000
Programmatic initialization:
PerformanceTrackerConfig.Initialize("MyLogger", enabled: true, slowThresholdMs: 5000);
Usage
Using statement (recommended)
using (var tracker = PerformanceTracker.Start("MyOperation"))
{
// Do work...
tracker.Complete();
}
Track synchronous actions
PerformanceTracker.Track("SendEmail", () =>
{
emailService.Send(message);
});
var total = PerformanceTracker.Track("CalculateTotal", () =>
{
return items.Sum(x => x.Price);
});
Track async operations
await PerformanceTracker.TrackAsync("FetchDataAsync", async () =>
{
await database.QueryAsync();
});
var user = await PerformanceTracker.TrackAsync("GetUserAsync", async () =>
{
return await api.GetUserAsync(userId);
});
Custom slow threshold per operation
using (var tracker = PerformanceTracker.Start("HeavyReport", slowThresholdMs: 10000))
{
// Flagged as SLOW only if > 10 seconds
tracker.Complete();
}
Exception handling
using (var tracker = PerformanceTracker.Start("RiskyOperation"))
{
try
{
DoSomethingRisky();
tracker.Complete();
}
catch (Exception ex)
{
tracker.SetException(ex);
throw;
}
}
Nested (hierarchical) operations
using (var parent = PerformanceTracker.Start("OrderProcessing"))
{
using (var child = PerformanceTracker.Start("ValidateOrder"))
{
// ParentTrackingId automatically set to parent.TrackingId
child.Complete();
}
using (var child = PerformanceTracker.Start("SaveOrder"))
{
child.Complete();
}
parent.Complete();
}
Accessing the current tracker
var current = PerformanceTracker.Current;
Console.WriteLine($"TrackingId: {current.TrackingId}");
Console.WriteLine($"Depth: {current.Depth}");
Disabling tracking globally
PerformanceTrackerConfig.Enabled = false;
Log Event Properties
Each tracked operation emits two structured log events: START and END.
START phase
| Property | Description |
|---|---|
TrackingId |
Unique identifier (GUID, 32 chars, no hyphens) |
ParentTrackingId |
Parent tracker ID (empty if root) |
Depth |
Nesting level (0 = root) |
Operation |
Operation name |
Phase |
START |
ThresholdMs |
Slow operation threshold |
CallerMember |
Calling method name |
CallerFile |
Source file path |
CallerLine |
Source line number |
END phase
All START properties, plus:
| Property | Description |
|---|---|
ElapsedMs |
Duration in milliseconds |
Status |
OK, COMPLETED, SLOW, or FAILED |
ExceptionType |
Exception type name (if failed) |
ExceptionMessage |
Exception message (if failed) |
Status Values
| Status | Condition |
|---|---|
OK |
Complete() called and elapsed < threshold |
SLOW |
Complete() called but elapsed >= threshold |
COMPLETED |
Disposed without explicit Complete() call, elapsed < threshold |
FAILED |
Exception was captured via SetException() |
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- NLog (>= 6.1.0)
- System.Configuration.ConfigurationManager (>= 10.0.2)
-
.NETStandard 2.0
- NLog (>= 6.1.0)
- System.Configuration.ConfigurationManager (>= 10.0.2)
-
net9.0
- NLog (>= 6.1.0)
- System.Configuration.ConfigurationManager (>= 10.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 149 | 2/6/2026 |
First release of BrainEnterprise.Library.Logging