Skip to content

Commit c9be295

Browse files
committed
Removed unnecessary logger extension
1 parent dd47ec1 commit c9be295

File tree

3 files changed

+31
-63
lines changed

3 files changed

+31
-63
lines changed

src/Microsoft.FeatureManagement.Telemetry.AzureMonitor/AzureMonitorEventPublisher.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,35 @@ private void HandleFeatureFlagEvent(ActivityEvent activityEvent)
9191
}
9292
}
9393

94-
_logger.LogFeatureEvaluation("FeatureEvaluation", properties);
94+
LogFeatureEvaluation("FeatureEvaluation", properties);
95+
}
96+
97+
private void LogFeatureEvaluation(string eventName, Dictionary<string, object> properties)
98+
{
99+
if (string.IsNullOrEmpty(eventName))
100+
{
101+
throw new ArgumentException("Event name cannot be null or empty.", nameof(eventName));
102+
}
103+
104+
// Build the message template dynamically with placeholders for each property
105+
var templateBuilder = new System.Text.StringBuilder("{microsoft.custom_event.name}");
106+
var args = new List<object> { eventName };
107+
108+
if (properties != null && properties.Count > 0)
109+
{
110+
foreach (var kvp in properties)
111+
{
112+
templateBuilder.Append($" {{{kvp.Key}}}");
113+
args.Add(kvp.Value);
114+
}
115+
}
116+
117+
// Use structured logging to ensure each property becomes a separate custom dimension
118+
_logger.Log(
119+
LogLevel.Information,
120+
new EventId(1, "microsoft.custom_event.name"),
121+
templateBuilder.ToString(),
122+
args.ToArray());
95123
}
96124
}
97125
}

src/Microsoft.FeatureManagement.Telemetry.AzureMonitor/LoggerExtensions.cs

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/Microsoft.FeatureManagement.Telemetry.AzureMonitor/README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,13 @@ services.AddFeatureManagement()
1717

1818
## How It Works
1919

20-
The package uses an `ActivityListener` to listen to feature evaluation events from the Microsoft.FeatureManagement library. When a feature flag is evaluated, the event is logged using a structured logging extension method:
20+
The package uses an `ActivityListener` to listen to feature evaluation events from the Microsoft.FeatureManagement library. When a feature flag is evaluated, the event is logged using structured logging.
2121

22-
```csharp
23-
_logger.LogFeatureEvaluation("FeatureEvaluation", properties);
24-
```
25-
26-
This extension method formats the event data properly for Azure Monitor ingestion using the `LoggerMessage.Define` pattern for high-performance logging. The properties dictionary is serialized to JSON and included in the log message.
22+
The event data is formatted properly for Azure Monitor ingestion using the `LoggerMessage.Define` pattern for high-performance logging. The properties dictionary is serialized to JSON and included in the log message.
2723

2824
## Key Components
2925

3026
- **AzureMonitorEventPublisher**: Listens to Activity events from feature management and logs them using the logger extension
31-
- **LoggerExtensions**: Provides optimized logging methods for feature evaluation events
3227
- **AzureMonitorHostedService**: Manages the lifecycle of the event publisher
3328
- **FeatureManagementBuilderExtensions**: Provides extension methods to register the telemetry components
3429

0 commit comments

Comments
 (0)