Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing File writing for EngineLogger #1415

Merged
merged 2 commits into from
Aug 18, 2023
Merged
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions src/DebugEngineHost/HostLogger.cs
Original file line number Diff line number Diff line change
@@ -54,7 +54,9 @@ public static ILogChannel GetNatvisLogChannel()

public static void Reset()
{
s_natvisLogChannel?.Close();
s_natvisLogChannel = null;
s_engineLogChannel?.Close();
s_engineLogChannel = null;
}
}
18 changes: 18 additions & 0 deletions src/MIDebugEngine/MIDebugCommandDispatcher.cs
Original file line number Diff line number Diff line change
@@ -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;
@@ -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;