Some more try...catches

This commit is contained in:
Jeff Kluge 2016-11-01 09:29:19 -07:00
parent 80ec02b4da
commit efa1cef866
2 changed files with 46 additions and 18 deletions

View file

@ -33,9 +33,16 @@ namespace Microsoft.DotNet.Tools.MSBuild
{ {
if (Telemetry.CurrentSessionId != null) if (Telemetry.CurrentSessionId != null)
{ {
Type loggerType = typeof(MSBuildLogger); try
{
Type loggerType = typeof(MSBuildLogger);
argsToForward = argsToForward.Concat(new[] {$"\"/Logger:{loggerType.FullName},{loggerType.GetTypeInfo().Assembly.Location};{Telemetry.CurrentSessionId}\""}); argsToForward = argsToForward.Concat(new[] { $"\"/Logger:{loggerType.FullName},{loggerType.GetTypeInfo().Assembly.Location}\"" });
}
catch (Exception)
{
// Exceptions during telemetry shouldn't cause anything else to fail
}
} }
_forwardingApp = new ForwardingApp( _forwardingApp = new ForwardingApp(

View file

@ -5,7 +5,6 @@ using System;
using Microsoft.Build.Framework; using Microsoft.Build.Framework;
using Microsoft.Build.Utilities; using Microsoft.Build.Utilities;
using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Configurer; using Microsoft.DotNet.Configurer;
namespace Microsoft.DotNet.Tools.MSBuild namespace Microsoft.DotNet.Tools.MSBuild
@ -17,34 +16,56 @@ namespace Microsoft.DotNet.Tools.MSBuild
public MSBuildLogger() public MSBuildLogger()
{ {
string sessionId = Environment.GetEnvironmentVariable(MSBuildForwardingApp.TelemetrySessionIdEnvironmentVariableName); try
if (sessionId != null)
{ {
_telemetry = new Telemetry(_sentinel, sessionId); string sessionId = Environment.GetEnvironmentVariable(MSBuildForwardingApp.TelemetrySessionIdEnvironmentVariableName);
if (sessionId != null)
{
_telemetry = new Telemetry(_sentinel, sessionId);
}
}
catch (Exception)
{
// Exceptions during telemetry shouldn't cause anything else to fail
} }
} }
public override void Initialize(IEventSource eventSource) public override void Initialize(IEventSource eventSource)
{ {
if (_telemetry != null) try
{ {
IEventSource2 eventSource2 = eventSource as IEventSource2; if (_telemetry != null && _telemetry.Enabled)
if (eventSource2 != null)
{ {
eventSource2.TelemetryLogged += (sender, telemetryEventArgs) => IEventSource2 eventSource2 = eventSource as IEventSource2;
if (eventSource2 != null)
{ {
Console.WriteLine($"Received telemetry event '{telemetryEventArgs.EventName}'"); eventSource2.TelemetryLogged += OnTelemetryLogged;
_telemetry.TrackEvent(telemetryEventArgs.EventName, telemetryEventArgs.Properties, measurements: null); }
};
} }
} }
catch(Exception)
{
// Exceptions during telemetry shouldn't cause anything else to fail
}
}
private void OnTelemetryLogged(object sender, TelemetryEventArgs args)
{
_telemetry.TrackEvent(args.EventName, args.Properties, measurements: null);
} }
public override void Shutdown() public override void Shutdown()
{ {
_sentinel?.Dispose(); try
{
_sentinel?.Dispose();
}
catch (Exception)
{
// Exceptions during telemetry shouldn't cause anything else to fail
}
base.Shutdown(); base.Shutdown();
} }