Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fixing File writing for EngineLogger (#1415)
* Fixing File writing for EngineLogger

With the Natvis Diagnostics Logger work, the file logger would fail
since it would not close the file.

This PR also runs 'File.CreateText' in MIDebugCommandDispatcher so
errors can be caught earlier and not set an invalid file path.
  • Loading branch information
WardenGnaw authored Aug 18, 2023
commit ad8e28a50a206ab2beca7c77e6737f6a305f7c12
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