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

@ -32,10 +32,17 @@ namespace Microsoft.DotNet.Tools.MSBuild
public MSBuildForwardingApp(IEnumerable<string> argsToForward) public MSBuildForwardingApp(IEnumerable<string> argsToForward)
{ {
if (Telemetry.CurrentSessionId != null) if (Telemetry.CurrentSessionId != null)
{
try
{ {
Type loggerType = typeof(MSBuildLogger); 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
@ -16,6 +15,8 @@ namespace Microsoft.DotNet.Tools.MSBuild
private readonly ITelemetry _telemetry; private readonly ITelemetry _telemetry;
public MSBuildLogger() public MSBuildLogger()
{
try
{ {
string sessionId = Environment.GetEnvironmentVariable(MSBuildForwardingApp.TelemetrySessionIdEnvironmentVariableName); string sessionId = Environment.GetEnvironmentVariable(MSBuildForwardingApp.TelemetrySessionIdEnvironmentVariableName);
@ -24,27 +25,47 @@ namespace Microsoft.DotNet.Tools.MSBuild
_telemetry = new Telemetry(_sentinel, sessionId); _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
{
if (_telemetry != null && _telemetry.Enabled)
{ {
IEventSource2 eventSource2 = eventSource as IEventSource2; IEventSource2 eventSource2 = eventSource as IEventSource2;
if (eventSource2 != null) if (eventSource2 != null)
{ {
eventSource2.TelemetryLogged += (sender, telemetryEventArgs) => eventSource2.TelemetryLogged += OnTelemetryLogged;
}
}
}
catch(Exception)
{ {
Console.WriteLine($"Received telemetry event '{telemetryEventArgs.EventName}'"); // Exceptions during telemetry shouldn't cause anything else to fail
_telemetry.TrackEvent(telemetryEventArgs.EventName, telemetryEventArgs.Properties, measurements: null);
};
} }
} }
private void OnTelemetryLogged(object sender, TelemetryEventArgs args)
{
_telemetry.TrackEvent(args.EventName, args.Properties, measurements: null);
} }
public override void Shutdown() public override void Shutdown()
{
try
{ {
_sentinel?.Dispose(); _sentinel?.Dispose();
}
catch (Exception)
{
// Exceptions during telemetry shouldn't cause anything else to fail
}
base.Shutdown(); base.Shutdown();
} }