Some more try...catches
This commit is contained in:
parent
80ec02b4da
commit
efa1cef866
2 changed files with 46 additions and 18 deletions
|
@ -5,7 +5,6 @@ using System;
|
|||
using Microsoft.Build.Framework;
|
||||
using Microsoft.Build.Utilities;
|
||||
using Microsoft.DotNet.Cli;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Configurer;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.MSBuild
|
||||
|
@ -17,36 +16,58 @@ namespace Microsoft.DotNet.Tools.MSBuild
|
|||
|
||||
public MSBuildLogger()
|
||||
{
|
||||
string sessionId = Environment.GetEnvironmentVariable(MSBuildForwardingApp.TelemetrySessionIdEnvironmentVariableName);
|
||||
|
||||
if (sessionId != null)
|
||||
try
|
||||
{
|
||||
_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)
|
||||
{
|
||||
if (_telemetry != null)
|
||||
try
|
||||
{
|
||||
IEventSource2 eventSource2 = eventSource as IEventSource2;
|
||||
|
||||
if (eventSource2 != null)
|
||||
if (_telemetry != null && _telemetry.Enabled)
|
||||
{
|
||||
eventSource2.TelemetryLogged += (sender, telemetryEventArgs) =>
|
||||
IEventSource2 eventSource2 = eventSource as IEventSource2;
|
||||
|
||||
if (eventSource2 != null)
|
||||
{
|
||||
Console.WriteLine($"Received telemetry event '{telemetryEventArgs.EventName}'");
|
||||
_telemetry.TrackEvent(telemetryEventArgs.EventName, telemetryEventArgs.Properties, measurements: null);
|
||||
};
|
||||
eventSource2.TelemetryLogged += OnTelemetryLogged;
|
||||
}
|
||||
}
|
||||
}
|
||||
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()
|
||||
{
|
||||
_sentinel?.Dispose();
|
||||
try
|
||||
{
|
||||
_sentinel?.Dispose();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Exceptions during telemetry shouldn't cause anything else to fail
|
||||
}
|
||||
|
||||
base.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue