diff --git a/src/VisualStudio/IntegrationTest/TestSetup/IntegrationTestServiceCommands.cs b/src/VisualStudio/IntegrationTest/TestSetup/IntegrationTestServiceCommands.cs index b9d76ea097bc72513b0062dcf80db4b97151b707..61bf5087321027d72fa8535071154e9e6a7e5e32 100644 --- a/src/VisualStudio/IntegrationTest/TestSetup/IntegrationTestServiceCommands.cs +++ b/src/VisualStudio/IntegrationTest/TestSetup/IntegrationTestServiceCommands.cs @@ -84,6 +84,8 @@ private void StartServiceCallback(object sender, EventArgs e) { if (_startMenuCmd.Enabled) { + IntegrationTestTraceListener.Install(); + _service = new IntegrationService(); _serviceChannel = new IpcServerChannel( diff --git a/src/VisualStudio/IntegrationTest/TestSetup/IntegrationTestServicePackage.cs b/src/VisualStudio/IntegrationTest/TestSetup/IntegrationTestServicePackage.cs index c414a0230804c32b6db1e1ea6f38e5fc7ae79796..e986b1308222fb5ae195e21adc2a1e632f2cd2b4 100644 --- a/src/VisualStudio/IntegrationTest/TestSetup/IntegrationTestServicePackage.cs +++ b/src/VisualStudio/IntegrationTest/TestSetup/IntegrationTestServicePackage.cs @@ -20,6 +20,7 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke { await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(true); await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); + cancellationToken.ThrowIfCancellationRequested(); IntegrationTestServiceCommands.Initialize(this); } diff --git a/src/VisualStudio/IntegrationTest/TestSetup/IntegrationTestTraceListener.cs b/src/VisualStudio/IntegrationTest/TestSetup/IntegrationTestTraceListener.cs new file mode 100644 index 0000000000000000000000000000000000000000..16e12f3011f735f965703b6f90bc6cf4b446ec9d --- /dev/null +++ b/src/VisualStudio/IntegrationTest/TestSetup/IntegrationTestTraceListener.cs @@ -0,0 +1,100 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using Microsoft.CodeAnalysis.ErrorReporting; + +namespace Microsoft.VisualStudio.IntegrationTest.Setup +{ + using Debugger = System.Diagnostics.Debugger; + + internal class IntegrationTestTraceListener : TraceListener + { + public override void Fail(string message, string detailMessage) + { + if (!string.IsNullOrEmpty(detailMessage)) + { + Exit(message + " " + detailMessage); + } + else + { + Exit(message); + } + } + + public override void Write(object o) + { + if (Debugger.IsLogging()) + { + Debugger.Log(0, null, o?.ToString()); + } + } + + public override void Write(object o, string category) + { + if (Debugger.IsLogging()) + { + Debugger.Log(0, category, o?.ToString()); + } + } + + public override void Write(string message) + { + if (Debugger.IsLogging()) + { + Debugger.Log(0, null, message); + } + } + + public override void Write(string message, string category) + { + if (Debugger.IsLogging()) + { + Debugger.Log(0, category, message); + } + } + + public override void WriteLine(object o) + { + if (Debugger.IsLogging()) + { + Debugger.Log(0, null, o?.ToString() + Environment.NewLine); + } + } + + public override void WriteLine(object o, string category) + { + if (Debugger.IsLogging()) + { + Debugger.Log(0, category, o?.ToString() + Environment.NewLine); + } + } + + public override void WriteLine(string message) + { + if (Debugger.IsLogging()) + { + Debugger.Log(0, null, message + Environment.NewLine); + } + } + + public override void WriteLine(string message, string category) + { + if (Debugger.IsLogging()) + { + Debugger.Log(0, category, message + Environment.NewLine); + } + } + + private static void Exit(string message) + { + FatalError.Report(new Exception(message)); + } + + internal static void Install() + { + Trace.Listeners.Clear(); + Trace.Listeners.Add(new IntegrationTestTraceListener()); + } + } +}