@@ -57,6 +57,8 @@ public void AppendFormatted<T>(T message, string? format) {
5757public interface ILog {
5858 void Log ( Guid correlationId , LogStringHandler message , SeverityLevel level , IReadOnlyDictionary < string , string > tags , string ? caller ) ;
5959 void LogEvent ( Guid correlationId , LogStringHandler evt , IReadOnlyDictionary < string , string > tags , IReadOnlyDictionary < string , double > ? metrics , string ? caller ) ;
60+ void LogMetric ( Guid correlationId , LogStringHandler metric , int value , IReadOnlyDictionary < string , string > ? customDimensions , IReadOnlyDictionary < string , string > tags , string ? caller ) ;
61+
6062 void LogException ( Guid correlationId , Exception ex , LogStringHandler message , IReadOnlyDictionary < string , string > tags , IReadOnlyDictionary < string , double > ? metrics , string ? caller ) ;
6163 void Flush ( ) ;
6264}
@@ -103,6 +105,17 @@ public void LogEvent(Guid correlationId, LogStringHandler evt, IReadOnlyDictiona
103105 _telemetryClient . TrackEvent ( telemetry ) ;
104106 }
105107
108+ public void LogMetric ( Guid correlationId , LogStringHandler metric , int value , IReadOnlyDictionary < string , string > ? customDimensions , IReadOnlyDictionary < string , string > tags , string ? caller ) {
109+ var telemetry = new MetricTelemetry ( metric . ToString ( ) , value , value , value , value , value ) ;
110+ // copy properties
111+ Copy ( telemetry . Properties , customDimensions ) ;
112+ telemetry . Properties [ "CorrelationId" ] = correlationId . ToString ( ) ;
113+ if ( caller is not null ) telemetry . Properties [ "CalledBy" ] = caller ;
114+ Copy ( telemetry . Properties , metric . Tags ) ;
115+
116+ _telemetryClient . TrackMetric ( telemetry ) ;
117+ }
118+
106119 public void LogException ( Guid correlationId , Exception ex , LogStringHandler message , IReadOnlyDictionary < string , string > tags , IReadOnlyDictionary < string , double > ? metrics , string ? caller ) {
107120 {
108121 var telemetry = new ExceptionTelemetry ( ex ) ;
@@ -160,11 +173,17 @@ public void Log(Guid correlationId, LogStringHandler message, SeverityLevel leve
160173 }
161174 }
162175
176+ public void LogMetric ( Guid correlationId , LogStringHandler metric , int value , IReadOnlyDictionary < string , string > ? customDimensions , IReadOnlyDictionary < string , string > tags , string ? caller ) {
177+ System . Console . Out . WriteLine ( $ "[{ correlationId } ][Metric] { metric } ") ;
178+ LogTags ( correlationId , tags ) ;
179+ }
180+
163181 public void LogEvent ( Guid correlationId , LogStringHandler evt , IReadOnlyDictionary < string , string > tags , IReadOnlyDictionary < string , double > ? metrics , string ? caller ) {
164182 System . Console . Out . WriteLine ( $ "[{ correlationId } ][Event] { evt } ") ;
165183 LogTags ( correlationId , tags ) ;
166184 LogMetrics ( correlationId , metrics ) ;
167185 }
186+
168187 public void LogException ( Guid correlationId , Exception ex , LogStringHandler message , IReadOnlyDictionary < string , string > tags , IReadOnlyDictionary < string , double > ? metrics , string ? caller ) {
169188 System . Console . Out . WriteLine ( $ "[{ correlationId } ][Exception] { message } :{ ex } ") ;
170189 LogTags ( correlationId , tags ) ;
@@ -183,6 +202,7 @@ public interface ILogTracer {
183202
184203 void Error ( Error error ) ;
185204 void Event ( LogStringHandler evt , IReadOnlyDictionary < string , double > ? metrics = null ) ;
205+ void Metric ( LogStringHandler metric , int value , IReadOnlyDictionary < string , string > ? customDimensions ) ;
186206 void Exception ( Exception ex , LogStringHandler message = $ "" , IReadOnlyDictionary < string , double > ? metrics = null ) ;
187207 void ForceFlush ( ) ;
188208 void Info ( LogStringHandler message ) ;
@@ -327,6 +347,13 @@ public void Event(LogStringHandler evt, IReadOnlyDictionary<string, double>? met
327347 }
328348 }
329349
350+ public void Metric ( LogStringHandler metric , int value , IReadOnlyDictionary < string , string > ? customDimensions ) {
351+ var caller = GetCaller ( ) ;
352+ foreach ( var logger in _loggers ) {
353+ logger . LogMetric ( CorrelationId , metric , value , customDimensions , Tags , caller ) ;
354+ }
355+ }
356+
330357 public void Exception ( Exception ex , LogStringHandler message , IReadOnlyDictionary < string , double > ? metrics ) {
331358 var caller = GetCaller ( ) ;
332359 foreach ( var logger in _loggers ) {
0 commit comments