This repository was archived by the owner on Aug 3, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
NuGet.Services.Contracts/Logging Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,6 +13,12 @@ void TrackMetric(
1313 double value ,
1414 IDictionary < string , string > properties = null ) ;
1515
16+ void TrackMetric (
17+ DateTimeOffset timestamp ,
18+ string metricName ,
19+ double value ,
20+ IDictionary < string , string > properties = null ) ;
21+
1622 void TrackException (
1723 Exception exception ,
1824 IDictionary < string , string > properties = null ,
Original file line number Diff line number Diff line change 44using System ;
55using System . Collections . Generic ;
66using Microsoft . ApplicationInsights ;
7+ using Microsoft . ApplicationInsights . DataContracts ;
78
89namespace NuGet . Services . Logging
910{
@@ -45,5 +46,36 @@ public void TrackMetric(
4546 // logging failed, don't allow exception to escape
4647 }
4748 }
49+
50+ public void TrackMetric (
51+ DateTimeOffset timestamp ,
52+ string metricName ,
53+ double value ,
54+ IDictionary < string , string > properties = null )
55+ {
56+ try
57+ {
58+ var metricTelemetry = new MetricTelemetry
59+ {
60+ Timestamp = timestamp ,
61+ Name = metricName ,
62+ Value = value
63+ } ;
64+
65+ if ( properties != null )
66+ {
67+ foreach ( var key in properties . Keys )
68+ {
69+ metricTelemetry . Properties . Add ( key , properties [ key ] ) ;
70+ }
71+ }
72+
73+ _telemetryClient . TrackMetric ( metricTelemetry ) ;
74+ }
75+ catch
76+ {
77+ // logging failed, don't allow exception to escape
78+ }
79+ }
4880 }
4981}
You can’t perform that action at this time.
0 commit comments