33
44using System ;
55using System . Collections . Generic ;
6- using System . Diagnostics ;
76using System . Runtime . InteropServices ;
87using System . Threading . Tasks ;
98using Microsoft . Extensions . Logging ;
@@ -78,13 +77,14 @@ private void InitializeTelemetry(string productVersion, IConfiguration config)
7877
7978 this . _commonProperties = new TelemetryCommonProperties ( productVersion , this . _client , config ) . GetTelemetryCommonProperties ( ) ;
8079 this . _commonMeasurements = new Dictionary < string , double > ( ) ;
80+ this . _logger . LogDebug ( $ "Telemetry Initialized. Session={ CurrentSessionId } ") ;
8181 }
8282 catch ( Exception e )
8383 {
84- this . _client . TrackException ( e ) ;
84+ this . _client ? . TrackException ( e ) ;
8585 this . _client = null ;
8686 // we don't want to fail the tool if telemetry fails.
87- Debug . Fail ( e . ToString ( ) ) ;
87+ this . _logger . LogError ( $ "Error initializing telemetry. Telemetry will be disabled. Message= { e . Message } " ) ;
8888 }
8989 }
9090
@@ -109,7 +109,7 @@ public void TrackEvent(TelemetryEventName eventName, IDictionary<TelemetryProper
109109 catch ( Exception ex )
110110 {
111111 // We don't want errors sending telemetry to break the app, so just log and move on
112- Debug . Fail ( $ "Error sending event { eventName } : { ex . Message } ") ;
112+ this . _logger . LogError ( $ "Error sending event { eventName } . Message= { ex . Message } ") ;
113113 }
114114 }
115115
@@ -134,7 +134,7 @@ public void TrackException(TelemetryErrorName errorName, Exception exception, ID
134134 catch ( Exception ex )
135135 {
136136 // We don't want errors sending telemetry to break the app, so just log and move on
137- Debug . Fail ( $ "Error sending exception event : { ex . Message } ") ;
137+ this . _logger . LogError ( $ "Error sending exception event. Message= { ex . Message } ") ;
138138 }
139139 }
140140
@@ -157,7 +157,7 @@ public void TrackDuration(TelemetryEventName eventName, long durationMs, IDictio
157157 catch ( Exception ex )
158158 {
159159 // We don't want errors sending telemetry to break the app, so just log and move on
160- Debug . Fail ( $ "Error sending event { eventName } : { ex . Message } ") ;
160+ this . _logger . LogError ( $ "Error sending event { eventName } . Message= { ex . Message } ") ;
161161 }
162162 }
163163
@@ -179,7 +179,7 @@ public void TrackCreate(CreateType type, IDictionary<TelemetryPropertyName, stri
179179 catch ( Exception ex )
180180 {
181181 // We don't want errors sending telemetry to break the app, so just log and move on
182- Debug . Fail ( $ "Error sending event Create : { ex . Message } ") ;
182+ this . _logger . LogError ( $ "Error sending event Create. Message= { ex . Message } ") ;
183183 }
184184 }
185185
@@ -201,7 +201,7 @@ public void TrackConvert(ConvertType type, IDictionary<TelemetryPropertyName, st
201201 catch ( Exception ex )
202202 {
203203 // We don't want errors sending telemetry to break the app, so just log and move on
204- Debug . Fail ( $ "Error sending event Create : { ex . Message } ") ;
204+ this . _logger . LogError ( $ "Error sending event Convert. Message= { ex . Message } ") ;
205205 }
206206 }
207207
@@ -225,7 +225,7 @@ private void TrackEventTask(
225225 }
226226 catch ( Exception e )
227227 {
228- Debug . Fail ( e . ToString ( ) ) ;
228+ this . _logger . LogError ( $ "Error sending event { eventName } . Message= { e . Message } " ) ;
229229 }
230230 }
231231
@@ -249,7 +249,7 @@ private void TrackExceptionTask(
249249 }
250250 catch ( Exception e )
251251 {
252- Debug . Fail ( e . ToString ( ) ) ;
252+ this . _logger . LogError ( $ "Error sending exception event. Message= { e . Message } " ) ;
253253 }
254254 }
255255
0 commit comments