Skip to content

Commit

Permalink
Merge pull request #1417 from microsoft/main
Browse files Browse the repository at this point in the history
Fixing File writing for EngineLogger (#1415)
  • Loading branch information
WardenGnaw authored Oct 5, 2023
2 parents c9f6960 + ad8e28a commit 388983f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/DebugEngineHost/HostLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public static ILogChannel GetNatvisLogChannel()

public static void Reset()
{
s_natvisLogChannel?.Close();
s_natvisLogChannel = null;
s_engineLogChannel?.Close();
s_engineLogChannel = null;
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/MIDebugEngine/MIDebugCommandDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using MICore;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -89,6 +90,23 @@ private static void process_DebuggerExitEvent(object sender, EventArgs e)

public static void EnableLogging(bool output, string logFile)
{
if (!string.IsNullOrEmpty(logFile))
{
string tempDirectory = Path.GetTempPath();
if (Path.IsPathRooted(logFile) || (!string.IsNullOrEmpty(tempDirectory) && Directory.Exists(tempDirectory)))
{
string filePath = Path.Combine(tempDirectory, logFile);

File.CreateText(filePath).Dispose(); // Test to see if we can create a text file in HostLogChannel. This will allow the error to be shown when enabling the setting.

logFile = filePath;
}
else
{
throw new ArgumentOutOfRangeException(nameof(logFile));
}
}

Logger.CmdLogInfo.logFile = logFile;
if (output)
Logger.CmdLogInfo.logToOutput = WriteLogToOutput;
Expand Down
10 changes: 10 additions & 0 deletions src/MIDebugPackage/MIDebugPackagePackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,16 @@ private void LaunchDebugTarget(string filePath, string options)
private void EnableLogging(bool sendToOutputWindow, string logFile)
{
ThreadHelper.ThrowIfNotOnUIThread();

IVsDebugger debugger = (IVsDebugger)GetService(typeof(IVsDebugger));
DBGMODE[] mode = new DBGMODE[] { DBGMODE.DBGMODE_Design };
int hr = debugger.GetMode(mode);

if (hr == VSConstants.S_OK && mode[0] != DBGMODE.DBGMODE_Design)
{
throw new ArgumentException("Unable to update MIDebugLog while debugging.");
}

try
{
MIDebugCommandDispatcher.EnableLogging(sendToOutputWindow, logFile);
Expand Down
2 changes: 1 addition & 1 deletion tools/Setup.csx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class Setup {
{
listFilePath = Path.Join(scriptDirectoryPath, "VS.list");
// Use <Configuration> folder.
binDirectoryPath = Path.Join(binDirectoryPath, Configuration.ToString());
binDirectoryPath = Path.Join(binDirectoryPath, "Lab." + Configuration.ToString());
}
else if (Client == Client.VSCode)
{
Expand Down
2 changes: 2 additions & 0 deletions tools/VS.list
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Microsoft.MICore.dll,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger
Microsoft.MICore.XmlSerializers.dll,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger
Microsoft.MIDebugEngine.dll,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger
Microsoft.MIDebugEngine.pkgdef,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger
Microsoft.MIDebugPackage.dll,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger
Microsoft.MIDebugPackage.pkgdef,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger
Microsoft.SSHDebugPS.dll,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger
Microsoft.SSHDebugPS.pkgdef,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger
OpenFolderSchema.json,bin,,\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger

0 comments on commit 388983f

Please sign in to comment.