未验证 提交 b451a121 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #33600 from sharwell/integration-trace-listener

Install a TraceListener for integration testing
......@@ -84,6 +84,8 @@ private void StartServiceCallback(object sender, EventArgs e)
{
if (_startMenuCmd.Enabled)
{
IntegrationTestTraceListener.Install();
_service = new IntegrationService();
_serviceChannel = new IpcServerChannel(
......
......@@ -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);
}
......
// 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());
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册