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
17 changes: 12 additions & 5 deletions OpenSharpCAD/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,20 @@ private void Compile()
}
private void LogException(Exception ex)
{
// Always output to console so the user can see what happened
Console.Error.WriteLine($"ERROR: {ex.Message}");
Console.Error.WriteLine(ex.StackTrace);

try
{
string logDir = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"CSharpCAD",
"logs"
);
string baseDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
if (string.IsNullOrEmpty(baseDir))
{
baseDir = Path.GetTempPath();
}

string logDir = Path.Combine(baseDir, "CSharpCAD", "logs");

if (!Directory.Exists(logDir))
{
Directory.CreateDirectory(logDir);
Expand Down
33 changes: 23 additions & 10 deletions OpenSharpCAD/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,32 @@ static void Main(string[] args)
}
catch (Exception ex)
{
string logDir = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"CSharpCAD",
"logs"
);
// Always output to console so the user can see what happened
Console.Error.WriteLine($"GLOBAL ERROR: {ex.Message}");
Console.Error.WriteLine(ex.StackTrace);

if (!Directory.Exists(logDir))
try
{
Directory.CreateDirectory(logDir);
string baseDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
if (string.IsNullOrEmpty(baseDir))
{
baseDir = Path.GetTempPath();
}

string logDir = Path.Combine(baseDir, "CSharpCAD", "logs");

if (!Directory.Exists(logDir))
{
Directory.CreateDirectory(logDir);
}
string logPath = Path.Combine(logDir, "errors.log");
string logMessage = $"[{DateTime.Now}] GLOBAL ERROR: {ex.Message}{Environment.NewLine}{ex.StackTrace}{Environment.NewLine}{new string('=', 30)}{Environment.NewLine}";
File.AppendAllText(logPath, logMessage);
}
catch (Exception logEx)
{
Console.Error.WriteLine($"Failed to write to log file: {logEx.Message}");
}
string logPath = Path.Combine(logDir, "errors.log");
string logMessage = $"[{DateTime.Now}] GLOBAL ERROR: {ex.Message}{Environment.NewLine}{ex.StackTrace}{Environment.NewLine}{new string('=', 30)}{Environment.NewLine}";
File.AppendAllText(logPath, logMessage);
}
}
}
Loading