diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt
index 155e493848..1a9d9a16a9 100644
--- a/.github/actions/spell-check/expect.txt
+++ b/.github/actions/spell-check/expect.txt
@@ -322,6 +322,7 @@ cxfksword
CXSCREEN
CXSMICON
CXVIRTUALSCREEN
+cxxopts
cyberrex
CYSCREEN
CYSMICON
diff --git a/doc/devdocs/logging.md b/doc/devdocs/logging.md
index 57f2d13844..f98a03820a 100644
--- a/doc/devdocs/logging.md
+++ b/doc/devdocs/logging.md
@@ -1,9 +1,61 @@
-# How to use
+# Logging
-We use the awesome [spdlog](https://github.com/gabime/spdlog) library for logging as a git submodule under the `deps` directory. To use it in your project, just include [spdlog.props](../../deps/spdlog.props) in a .vcxproj like this:
+Logging plays an important part in determining bugs in our code. It provides context for the developers about where and when errors occur.
+
+## Where are the logs saved
+
+* Most of the logs are saved under `%LOCALAPPDATA%/Microsoft/PowerToys`.
+* For low-privilege processes (like preview handlers) the logs are saved under `%USERPROFILE%/AppData/LocalLow/Microsoft/PowerToys`.
+
+Logs are normally in a subfolder with the module name as title.
+
+The [BugReportTool](/tools/BugReportTool) will take logs from both locations when executed.
+
+## Using a logger in a project
+
+### Spdlog
+
+In C++ projects we use the awesome [spdlog](https://github.com/gabime/spdlog) library for logging as a git submodule under the `deps` directory. To use it in your project, just include [spdlog.props](/deps/spdlog.props) in a .vcxproj like this:
```xml
```
It'll add the required include dirs and link the library binary itself.
+### PowerToys Logger in ManagedCommon
+
+For C# projects there is a static logger class in Managed Common called `Logger`.
+
+To use it, add a project reference to `ManagedCommon` and add the following line of code to all the files using the logger:
+
+```Csharp
+using ManagedCommon;
+```
+
+In the `Main` function (or a function with a similar meaning (like `App` in a `App.xaml.cs` file)) you have to call `InitializeLogger` and specify the location where the logs will be saved (always use a path scheme similar to this example):
+
+```Csharp
+Logger.InitializeLogger("\\FancyZones\\Editor\\Logs");
+```
+
+For a low-privilege process you have to set the optional second parameter to `true`:
+
+```Csharp
+Logger.InitializeLogger("\\FileExplorer\\Monaco\\Logs", true);
+```
+
+The `Logger` class contains the following logging functions:
+
+```Csharp
+// Logs an error that the utility encountered
+Logger.LogError(string message);
+Logger.LogError(string message, Exception ex);
+// Logs an error that isn't that grave
+Logger.LogWarning(string message);
+// Logs what the app is doing at the moment
+Logger.LogInfo(string message);
+// Like LogInfo just with infos important for debugging
+Logger.LogDebug(string message);
+// Logs the current state of the utility.
+Logger.LogTrace();
+```
diff --git a/installer/PowerToysSetup/FileLocksmith.wxs b/installer/PowerToysSetup/FileLocksmith.wxs
index a0e34f7051..9c3d2848ca 100644
--- a/installer/PowerToysSetup/FileLocksmith.wxs
+++ b/installer/PowerToysSetup/FileLocksmith.wxs
@@ -4,7 +4,7 @@
-
+
diff --git a/installer/PowerToysSetup/MeasureTool.wxs b/installer/PowerToysSetup/MeasureTool.wxs
index d6223c11ea..38ed627afe 100644
--- a/installer/PowerToysSetup/MeasureTool.wxs
+++ b/installer/PowerToysSetup/MeasureTool.wxs
@@ -4,7 +4,7 @@
-
+
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Logs/Logger.cs b/src/common/ManagedCommon/Logger.cs
similarity index 68%
rename from src/modules/fancyzones/editor/FancyZonesEditor/Logs/Logger.cs
rename to src/common/ManagedCommon/Logger.cs
index 1998ddd516..0d6cc32f2d 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/Logs/Logger.cs
+++ b/src/common/ManagedCommon/Logger.cs
@@ -8,16 +8,16 @@ using System.Globalization;
using System.IO;
using System.IO.Abstractions;
using System.Reflection;
+using System.Runtime.Serialization;
using interop;
-namespace FancyZonesEditor.Logs
+namespace ManagedCommon
{
public static class Logger
{
private static readonly IFileSystem _fileSystem = new FileSystem();
private static readonly Assembly Assembly = Assembly.GetExecutingAssembly();
- public static readonly string Version = FileVersionInfo.GetVersionInfo(Assembly.Location).ProductVersion;
- private static readonly string ApplicationLogPath = Path.Combine(Constants.AppDataPath(), "FancyZones\\Editor\\Logs\\", Version);
+ private static readonly string Version = FileVersionInfo.GetVersionInfo(Assembly.Location).ProductVersion;
private static readonly string Error = "Error";
private static readonly string Warning = "Warning";
@@ -25,15 +25,29 @@ namespace FancyZonesEditor.Logs
private static readonly string Debug = "Debug";
private static readonly string TraceFlag = "Trace";
- static Logger()
+ ///
+ /// Initializes the logger and sets the path for logging.
+ ///
+ /// InitializeLogger("\\FancyZones\\Editor\\Logs")
+ /// The path to the log files folder.
+ /// If the process using Logger is a low-privilege process.
+ public static void InitializeLogger(string applicationLogPath, bool isLocalLow = false)
{
- if (!_fileSystem.Directory.Exists(ApplicationLogPath))
+ if (isLocalLow)
{
- _fileSystem.Directory.CreateDirectory(ApplicationLogPath);
+ applicationLogPath = Environment.GetEnvironmentVariable("userprofile") + "\\appdata\\LocalLow\\Microsoft\\PowerToys" + applicationLogPath + "\\" + Version;
+ }
+ else
+ {
+ applicationLogPath = Constants.AppDataPath() + applicationLogPath + "\\" + Version;
}
- // Using InvariantCulture since this is used for a log file name
- var logFilePath = _fileSystem.Path.Combine(ApplicationLogPath, "Log_" + DateTime.Now.ToString(@"yyyy-MM-dd", CultureInfo.InvariantCulture) + ".txt");
+ if (!_fileSystem.Directory.Exists(applicationLogPath))
+ {
+ _fileSystem.Directory.CreateDirectory(applicationLogPath);
+ }
+
+ var logFilePath = _fileSystem.Path.Combine(applicationLogPath, "Log_" + DateTime.Now.ToString(@"yyyy-MM-dd", CultureInfo.InvariantCulture) + ".txt");
Trace.Listeners.Add(new TextWriterTraceListener(logFilePath));
@@ -91,7 +105,7 @@ namespace FancyZonesEditor.Logs
private static string GetCallerInfo()
{
- StackTrace stackTrace = new StackTrace();
+ StackTrace stackTrace = new();
var methodName = stackTrace.GetFrame(3)?.GetMethod();
var className = methodName?.DeclaringType.Name;
diff --git a/src/common/ManagedCommon/ManagedCommon.csproj b/src/common/ManagedCommon/ManagedCommon.csproj
index 7f8419d98d..05f9bd34e1 100644
--- a/src/common/ManagedCommon/ManagedCommon.csproj
+++ b/src/common/ManagedCommon/ManagedCommon.csproj
@@ -13,10 +13,12 @@
+
+
diff --git a/src/modules/FileLocksmith/FileLocksmithUI/App.xaml.cs b/src/modules/FileLocksmith/FileLocksmithUI/App.xaml.cs
index a55714470a..15312c5969 100644
--- a/src/modules/FileLocksmith/FileLocksmithUI/App.xaml.cs
+++ b/src/modules/FileLocksmith/FileLocksmithUI/App.xaml.cs
@@ -4,7 +4,6 @@
using System;
using System.Linq;
-using FileLocksmithUI.Helpers;
using ManagedCommon;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;
@@ -23,6 +22,8 @@ namespace FileLocksmithUI
///
public App()
{
+ Logger.InitializeLogger("\\File Locksmith\\FileLocksmithUI\\Logs");
+
this.InitializeComponent();
}
diff --git a/src/modules/FileLocksmith/FileLocksmithUI/Helpers/Logger.cs b/src/modules/FileLocksmith/FileLocksmithUI/Helpers/Logger.cs
deleted file mode 100644
index 2ec357c3cf..0000000000
--- a/src/modules/FileLocksmith/FileLocksmithUI/Helpers/Logger.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (c) Microsoft Corporation
-// The Microsoft Corporation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using System.Diagnostics;
-using System.Globalization;
-using System.IO;
-
-namespace FileLocksmithUI.Helpers
-{
- public static class Logger
- {
- private static readonly string ApplicationLogPath = Path.Combine(interop.Constants.AppDataPath(), "File Locksmith\\FileLocksmithUI\\Logs");
-
- static Logger()
- {
- if (!Directory.Exists(ApplicationLogPath))
- {
- Directory.CreateDirectory(ApplicationLogPath);
- }
-
- // Using InvariantCulture since this is used for a log file name
- var logFilePath = Path.Combine(ApplicationLogPath, "Log_" + DateTime.Now.ToString(@"yyyy-MM-dd", CultureInfo.InvariantCulture) + ".txt");
-
- Trace.Listeners.Add(new TextWriterTraceListener(logFilePath));
-
- Trace.AutoFlush = true;
- }
-
- public static void LogError(string message)
- {
- Log(message, "ERROR");
- }
-
- public static void LogError(string message, Exception ex)
- {
- Log(
- message + Environment.NewLine +
- ex?.Message + Environment.NewLine +
- "Inner exception: " + Environment.NewLine +
- ex?.InnerException?.Message + Environment.NewLine +
- "Stack trace: " + Environment.NewLine +
- ex?.StackTrace,
- "ERROR");
- }
-
- public static void LogWarning(string message)
- {
- Log(message, "WARNING");
- }
-
- public static void LogInfo(string message)
- {
- Log(message, "INFO");
- }
-
- private static void Log(string message, string type)
- {
- Trace.WriteLine(type + ": " + DateTime.Now.TimeOfDay);
- Trace.Indent();
- Trace.WriteLine(GetCallerInfo());
- Trace.WriteLine(message);
- Trace.Unindent();
- }
-
- private static string GetCallerInfo()
- {
- StackTrace stackTrace = new StackTrace();
-
- var methodName = stackTrace.GetFrame(3)?.GetMethod();
- var className = methodName?.DeclaringType.Name;
- return "[Method]: " + methodName?.Name + " [Class]: " + className;
- }
- }
-}
diff --git a/src/modules/FileLocksmith/FileLocksmithUI/ViewModels/MainViewModel.cs b/src/modules/FileLocksmith/FileLocksmithUI/ViewModels/MainViewModel.cs
index 6e0adf2dcf..d473a05c58 100644
--- a/src/modules/FileLocksmith/FileLocksmithUI/ViewModels/MainViewModel.cs
+++ b/src/modules/FileLocksmith/FileLocksmithUI/ViewModels/MainViewModel.cs
@@ -12,7 +12,7 @@ using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using FileLocksmith.Interop;
-using global::FileLocksmithUI.Helpers;
+using ManagedCommon;
namespace PowerToys.FileLocksmithUI.ViewModels
{
diff --git a/src/modules/Hosts/Hosts/Helpers/HostsService.cs b/src/modules/Hosts/Hosts/Helpers/HostsService.cs
index 32f3ef52cb..7d90e57144 100644
--- a/src/modules/Hosts/Hosts/Helpers/HostsService.cs
+++ b/src/modules/Hosts/Hosts/Helpers/HostsService.cs
@@ -15,6 +15,7 @@ using System.Threading;
using System.Threading.Tasks;
using Hosts.Models;
using Hosts.Settings;
+using ManagedCommon;
using Microsoft.Win32;
using Settings.UI.Library.Enumerations;
diff --git a/src/modules/Hosts/Hosts/Helpers/Logger.cs b/src/modules/Hosts/Hosts/Helpers/Logger.cs
deleted file mode 100644
index 8a4cd558ce..0000000000
--- a/src/modules/Hosts/Hosts/Helpers/Logger.cs
+++ /dev/null
@@ -1,80 +0,0 @@
-// Copyright (c) Microsoft Corporation
-// The Microsoft Corporation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using System.Diagnostics;
-using System.Globalization;
-using System.IO;
-using System.IO.Abstractions;
-using interop;
-
-namespace Hosts.Helpers
-{
- // TODO: use centralized logger https://github.com/microsoft/PowerToys/issues/19650
- public static class Logger
- {
- private static readonly IFileSystem _fileSystem = new FileSystem();
- private static readonly string ApplicationLogPath = Path.Combine(Constants.AppDataPath(), "Hosts\\Logs");
-
- static Logger()
- {
- if (!_fileSystem.Directory.Exists(ApplicationLogPath))
- {
- _fileSystem.Directory.CreateDirectory(ApplicationLogPath);
- }
-
- // Using InvariantCulture since this is used for a log file name
- var logFilePath = _fileSystem.Path.Combine(ApplicationLogPath, "Log_" + DateTime.Now.ToString(@"yyyy-MM-dd", CultureInfo.InvariantCulture) + ".txt");
-
- Trace.Listeners.Add(new TextWriterTraceListener(logFilePath));
-
- Trace.AutoFlush = true;
- }
-
- public static void LogError(string message)
- {
- Log(message, "ERROR");
- }
-
- public static void LogError(string message, Exception ex)
- {
- Log(
- message + Environment.NewLine +
- ex?.Message + Environment.NewLine +
- "Inner exception: " + Environment.NewLine +
- ex?.InnerException?.Message + Environment.NewLine +
- "Stack trace: " + Environment.NewLine +
- ex?.StackTrace,
- "ERROR");
- }
-
- public static void LogWarning(string message)
- {
- Log(message, "WARNING");
- }
-
- public static void LogInfo(string message)
- {
- Log(message, "INFO");
- }
-
- private static void Log(string message, string type)
- {
- Trace.WriteLine(type + ": " + DateTime.Now.TimeOfDay);
- Trace.Indent();
- Trace.WriteLine(GetCallerInfo());
- Trace.WriteLine(message);
- Trace.Unindent();
- }
-
- private static string GetCallerInfo()
- {
- StackTrace stackTrace = new StackTrace();
-
- var methodName = stackTrace.GetFrame(3)?.GetMethod();
- var className = methodName?.DeclaringType.Name;
- return "[Method]: " + methodName?.Name + " [Class]: " + className;
- }
- }
-}
diff --git a/src/modules/Hosts/Hosts/Program.cs b/src/modules/Hosts/Hosts/Program.cs
index 32b46a7a44..4b41f3c71a 100644
--- a/src/modules/Hosts/Hosts/Program.cs
+++ b/src/modules/Hosts/Hosts/Program.cs
@@ -4,7 +4,7 @@
using System;
using System.Threading;
-using Hosts.Helpers;
+using ManagedCommon;
using Microsoft.UI.Dispatching;
using Microsoft.Windows.AppLifecycle;
@@ -15,6 +15,8 @@ namespace Hosts
[STAThread]
public static void Main(string[] args)
{
+ Logger.InitializeLogger("\\Hosts\\Logs");
+
WinRT.ComWrappersSupport.InitializeComWrappers();
if (PowerToys.GPOWrapper.GPOWrapper.GetConfiguredHostsFileEditorEnabledValue() == PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
diff --git a/src/modules/Hosts/Hosts/Settings/UserSettings.cs b/src/modules/Hosts/Hosts/Settings/UserSettings.cs
index 89883b510f..f1e47e6019 100644
--- a/src/modules/Hosts/Hosts/Settings/UserSettings.cs
+++ b/src/modules/Hosts/Hosts/Settings/UserSettings.cs
@@ -5,6 +5,7 @@
using System;
using System.IO.Abstractions;
using System.Threading;
+using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Settings.UI.Library.Enumerations;
diff --git a/src/modules/Hosts/Hosts/ViewModels/MainViewModel.cs b/src/modules/Hosts/Hosts/ViewModels/MainViewModel.cs
index 05fd3c1d16..0896e9c115 100644
--- a/src/modules/Hosts/Hosts/ViewModels/MainViewModel.cs
+++ b/src/modules/Hosts/Hosts/ViewModels/MainViewModel.cs
@@ -17,6 +17,7 @@ using CommunityToolkit.WinUI.UI;
using Hosts.Helpers;
using Hosts.Models;
using Hosts.Settings;
+using ManagedCommon;
using Microsoft.UI.Dispatching;
namespace Hosts.ViewModels
diff --git a/src/modules/Hosts/Hosts/Views/MainPage.xaml.cs b/src/modules/Hosts/Hosts/Views/MainPage.xaml.cs
index 0d1ec6d1c9..37303b358b 100644
--- a/src/modules/Hosts/Hosts/Views/MainPage.xaml.cs
+++ b/src/modules/Hosts/Hosts/Views/MainPage.xaml.cs
@@ -6,10 +6,10 @@ using System;
using System.Threading.Tasks;
using System.Windows.Input;
using CommunityToolkit.Mvvm.Input;
-using Hosts.Helpers;
using Hosts.Models;
using Hosts.Settings;
using Hosts.ViewModels;
+using ManagedCommon;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
diff --git a/src/modules/MeasureTool/MeasureToolUI/App.xaml.cs b/src/modules/MeasureTool/MeasureToolUI/App.xaml.cs
index f81bc2047f..9cb26f54f5 100644
--- a/src/modules/MeasureTool/MeasureToolUI/App.xaml.cs
+++ b/src/modules/MeasureTool/MeasureToolUI/App.xaml.cs
@@ -4,7 +4,6 @@
using System;
using ManagedCommon;
-using MeasureToolUI.Helpers;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;
@@ -22,6 +21,8 @@ namespace MeasureToolUI
///
public App()
{
+ Logger.InitializeLogger("\\Measure Tool\\MeasureToolUI\\Logs");
+
this.InitializeComponent();
}
diff --git a/src/modules/MeasureTool/MeasureToolUI/Logger.cs b/src/modules/MeasureTool/MeasureToolUI/Logger.cs
deleted file mode 100644
index 30fb1b43a4..0000000000
--- a/src/modules/MeasureTool/MeasureToolUI/Logger.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (c) Microsoft Corporation
-// The Microsoft Corporation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using System.Diagnostics;
-using System.Globalization;
-using System.IO;
-
-namespace MeasureToolUI.Helpers
-{
- public static class Logger
- {
- private static readonly string ApplicationLogPath = Path.Combine(interop.Constants.AppDataPath(), "Measure Tool\\MeasureToolUI\\Logs");
-
- static Logger()
- {
- if (!Directory.Exists(ApplicationLogPath))
- {
- Directory.CreateDirectory(ApplicationLogPath);
- }
-
- // Using InvariantCulture since this is used for a log file name
- var logFilePath = Path.Combine(ApplicationLogPath, "Log_" + DateTime.Now.ToString(@"yyyy-MM-dd", CultureInfo.InvariantCulture) + ".txt");
-
- Trace.Listeners.Add(new TextWriterTraceListener(logFilePath));
-
- Trace.AutoFlush = true;
- }
-
- public static void LogError(string message)
- {
- Log(message, "ERROR");
- }
-
- public static void LogError(string message, Exception ex)
- {
- Log(
- message + Environment.NewLine +
- ex?.Message + Environment.NewLine +
- "Inner exception: " + Environment.NewLine +
- ex?.InnerException?.Message + Environment.NewLine +
- "Stack trace: " + Environment.NewLine +
- ex?.StackTrace,
- "ERROR");
- }
-
- public static void LogWarning(string message)
- {
- Log(message, "WARNING");
- }
-
- public static void LogInfo(string message)
- {
- Log(message, "INFO");
- }
-
- private static void Log(string message, string type)
- {
- Trace.WriteLine(type + ": " + DateTime.Now.TimeOfDay);
- Trace.Indent();
- Trace.WriteLine(GetCallerInfo());
- Trace.WriteLine(message);
- Trace.Unindent();
- }
-
- private static string GetCallerInfo()
- {
- StackTrace stackTrace = new StackTrace();
-
- var methodName = stackTrace.GetFrame(3)?.GetMethod();
- var className = methodName?.DeclaringType.Name;
- return "[Method]: " + methodName?.Name + " [Class]: " + className;
- }
- }
-}
diff --git a/src/modules/MouseUtils/MouseJumpUI/Helpers/Logger.cs b/src/modules/MouseUtils/MouseJumpUI/Helpers/Logger.cs
deleted file mode 100644
index 84e2c29f70..0000000000
--- a/src/modules/MouseUtils/MouseJumpUI/Helpers/Logger.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (c) Microsoft Corporation
-// The Microsoft Corporation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using System.Diagnostics;
-using System.Globalization;
-using System.IO;
-
-namespace MouseJumpUI.Helpers
-{
- // TODO: use centralized logger https://github.com/microsoft/PowerToys/issues/19650
- public static class Logger
- {
- private static readonly string ApplicationLogPath = Path.Combine(interop.Constants.AppDataPath(), "MouseJump\\Logs");
-
- static Logger()
- {
- if (!Directory.Exists(ApplicationLogPath))
- {
- Directory.CreateDirectory(ApplicationLogPath);
- }
-
- // Using InvariantCulture since this is used for a log file name
- var logFilePath = Path.Combine(ApplicationLogPath, "Log_" + DateTime.Now.ToString(@"yyyy-MM-dd", CultureInfo.InvariantCulture) + ".txt");
-
- Trace.Listeners.Add(new TextWriterTraceListener(logFilePath));
-
- Trace.AutoFlush = true;
- }
-
- public static void LogError(string message)
- {
- Log(message, "ERROR");
- }
-
- public static void LogError(string message, Exception ex)
- {
- Log(
- message + Environment.NewLine +
- ex?.Message + Environment.NewLine +
- "Inner exception: " + Environment.NewLine +
- ex?.InnerException?.Message + Environment.NewLine +
- "Stack trace: " + Environment.NewLine +
- ex?.StackTrace,
- "ERROR");
- }
-
- public static void LogWarning(string message)
- {
- Log(message, "WARNING");
- }
-
- public static void LogInfo(string message)
- {
- Log(message, "INFO");
- }
-
- private static void Log(string message, string type)
- {
- Trace.WriteLine(type + ": " + DateTime.Now.TimeOfDay);
- Trace.Indent();
- Trace.WriteLine(GetCallerInfo());
- Trace.WriteLine(message);
- Trace.Unindent();
- }
-
- private static string GetCallerInfo()
- {
- var stackTrace = new StackTrace();
- var methodName = stackTrace.GetFrame(3)?.GetMethod();
- var className = methodName?.DeclaringType?.Name;
- return "[Method]: " + methodName?.Name + " [Class]: " + className;
- }
- }
-}
diff --git a/src/modules/MouseUtils/MouseJumpUI/MainForm.cs b/src/modules/MouseUtils/MouseJumpUI/MainForm.cs
index 542046147c..b068989062 100644
--- a/src/modules/MouseUtils/MouseJumpUI/MainForm.cs
+++ b/src/modules/MouseUtils/MouseJumpUI/MainForm.cs
@@ -8,6 +8,7 @@ using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Windows.Forms;
+using ManagedCommon;
using MouseJumpUI.Drawing.Models;
using MouseJumpUI.Helpers;
using MouseJumpUI.NativeMethods.Core;
diff --git a/src/modules/MouseUtils/MouseJumpUI/Program.cs b/src/modules/MouseUtils/MouseJumpUI/Program.cs
index 6770a0a7be..f5932c13c0 100644
--- a/src/modules/MouseUtils/MouseJumpUI/Program.cs
+++ b/src/modules/MouseUtils/MouseJumpUI/Program.cs
@@ -4,7 +4,7 @@
using System;
using System.Windows.Forms;
-using MouseJumpUI.Helpers;
+using ManagedCommon;
namespace MouseJumpUI;
@@ -16,6 +16,8 @@ internal static class Program
[STAThread]
private static void Main()
{
+ Logger.InitializeLogger("\\MouseJump\\Logs");
+
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
diff --git a/src/modules/PowerOCR/PowerOCR/App.xaml.cs b/src/modules/PowerOCR/PowerOCR/App.xaml.cs
index 7a83b93897..60c6c03b81 100644
--- a/src/modules/PowerOCR/PowerOCR/App.xaml.cs
+++ b/src/modules/PowerOCR/PowerOCR/App.xaml.cs
@@ -26,6 +26,8 @@ public partial class App : Application, IDisposable
public App()
{
+ Logger.InitializeLogger("\\TextExtractor\\Logs");
+
NativeThreadCTS = new CancellationTokenSource();
}
diff --git a/src/modules/PowerOCR/PowerOCR/Helpers/Logger.cs b/src/modules/PowerOCR/PowerOCR/Helpers/Logger.cs
deleted file mode 100644
index 447ff6f97b..0000000000
--- a/src/modules/PowerOCR/PowerOCR/Helpers/Logger.cs
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright (c) Microsoft Corporation
-// The Microsoft Corporation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using System.Diagnostics;
-using System.Globalization;
-using System.IO;
-using System.IO.Abstractions;
-using interop;
-
-namespace PowerOCR.Helpers
-{
- public static class Logger
- {
- private static readonly IFileSystem _fileSystem = new FileSystem();
- private static readonly string ApplicationLogPath = Path.Combine(Constants.AppDataPath(), "TextExtractor\\Logs");
-
- static Logger()
- {
- if (!_fileSystem.Directory.Exists(ApplicationLogPath))
- {
- _fileSystem.Directory.CreateDirectory(ApplicationLogPath);
- }
-
- // Using InvariantCulture since this is used for a log file name
- var logFilePath = _fileSystem.Path.Combine(ApplicationLogPath, "Log_" + DateTime.Now.ToString(@"yyyy-MM-dd", CultureInfo.InvariantCulture) + ".txt");
-
- Trace.Listeners.Add(new TextWriterTraceListener(logFilePath));
-
- Trace.AutoFlush = true;
- }
-
- public static void LogError(string message)
- {
- Log(message, "ERROR");
- }
-
- public static void LogError(string message, Exception ex)
- {
- Log(
- message + Environment.NewLine +
- ex?.Message + Environment.NewLine +
- "Inner exception: " + Environment.NewLine +
- ex?.InnerException?.Message + Environment.NewLine +
- "Stack trace: " + Environment.NewLine +
- ex?.StackTrace,
- "ERROR");
- }
-
- public static void LogWarning(string message)
- {
- Log(message, "WARNING");
- }
-
- public static void LogInfo(string message)
- {
- Log(message, "INFO");
- }
-
- private static void Log(string message, string type)
- {
- Trace.WriteLine(type + ": " + DateTime.Now.TimeOfDay);
- Trace.Indent();
- Trace.WriteLine(GetCallerInfo());
- Trace.WriteLine(message);
- Trace.Unindent();
- }
-
- private static string GetCallerInfo()
- {
- StackTrace stackTrace = new StackTrace();
-
- var methodName = stackTrace.GetFrame(3)?.GetMethod();
- var className = methodName?.DeclaringType?.Name;
- return "[Method]: " + methodName?.Name + " [Class]: " + className;
- }
- }
-}
diff --git a/src/modules/PowerOCR/PowerOCR/Helpers/WindowUtilities.cs b/src/modules/PowerOCR/PowerOCR/Helpers/WindowUtilities.cs
index d4301defc5..939f987ace 100644
--- a/src/modules/PowerOCR/PowerOCR/Helpers/WindowUtilities.cs
+++ b/src/modules/PowerOCR/PowerOCR/Helpers/WindowUtilities.cs
@@ -4,6 +4,7 @@
using System.Windows;
using System.Windows.Forms;
+using ManagedCommon;
using Microsoft.PowerToys.Telemetry;
using PowerOCR.Helpers;
diff --git a/src/modules/PowerOCR/PowerOCR/OCROverlay.xaml.cs b/src/modules/PowerOCR/PowerOCR/OCROverlay.xaml.cs
index 4a0f8811c9..66e1374569 100644
--- a/src/modules/PowerOCR/PowerOCR/OCROverlay.xaml.cs
+++ b/src/modules/PowerOCR/PowerOCR/OCROverlay.xaml.cs
@@ -9,6 +9,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
+using ManagedCommon;
using Microsoft.PowerToys.Telemetry;
using PowerOCR.Helpers;
using PowerOCR.Settings;
diff --git a/src/modules/PowerOCR/PowerOCR/Settings/UserSettings.cs b/src/modules/PowerOCR/PowerOCR/Settings/UserSettings.cs
index 4019c0f354..d36bf19faa 100644
--- a/src/modules/PowerOCR/PowerOCR/Settings/UserSettings.cs
+++ b/src/modules/PowerOCR/PowerOCR/Settings/UserSettings.cs
@@ -7,6 +7,7 @@ using System.ComponentModel.Composition;
using System.IO;
using System.IO.Abstractions;
using System.Threading;
+using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
diff --git a/src/modules/awake/Awake/Program.cs b/src/modules/awake/Awake/Program.cs
index 1d016300ff..b2f1244505 100644
--- a/src/modules/awake/Awake/Program.cs
+++ b/src/modules/awake/Awake/Program.cs
@@ -25,6 +25,7 @@ using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.System.Console;
using Windows.Win32.System.Power;
+using Logger = NLog.Logger;
#pragma warning disable CS8602 // Dereference of a possibly null reference.
#pragma warning disable CS8603 // Possible null reference return.
diff --git a/src/modules/colorPicker/ColorPickerUI/App.xaml.cs b/src/modules/colorPicker/ColorPickerUI/App.xaml.cs
index 2a448c50e2..9097ec9c29 100644
--- a/src/modules/colorPicker/ColorPickerUI/App.xaml.cs
+++ b/src/modules/colorPicker/ColorPickerUI/App.xaml.cs
@@ -6,7 +6,6 @@ using System;
using System.ComponentModel.Composition;
using System.Threading;
using System.Windows;
-using ColorPicker.Helpers;
using ColorPicker.Mouse;
using Common.UI;
using ManagedCommon;
diff --git a/src/modules/colorPicker/ColorPickerUI/Behaviors/ChangeWindowPositionBehavior.cs b/src/modules/colorPicker/ColorPickerUI/Behaviors/ChangeWindowPositionBehavior.cs
index d8e1eb85f9..41f27ea3eb 100644
--- a/src/modules/colorPicker/ColorPickerUI/Behaviors/ChangeWindowPositionBehavior.cs
+++ b/src/modules/colorPicker/ColorPickerUI/Behaviors/ChangeWindowPositionBehavior.cs
@@ -5,6 +5,7 @@
using System.Windows;
using ColorPicker.Helpers;
using ColorPicker.Mouse;
+using ManagedCommon;
using Microsoft.Xaml.Behaviors;
namespace ColorPicker.Behaviors
diff --git a/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs b/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs
index de9847ceb0..fb10b99b75 100644
--- a/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs
+++ b/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs
@@ -9,6 +9,7 @@ using System.Windows.Interop;
using ColorPicker.Settings;
using ColorPicker.ViewModelContracts;
using Common.UI;
+using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
namespace ColorPicker.Helpers
diff --git a/src/modules/colorPicker/ColorPickerUI/Helpers/ClipboardHelper.cs b/src/modules/colorPicker/ColorPickerUI/Helpers/ClipboardHelper.cs
index 627bd382c2..1f87d19fa3 100644
--- a/src/modules/colorPicker/ColorPickerUI/Helpers/ClipboardHelper.cs
+++ b/src/modules/colorPicker/ColorPickerUI/Helpers/ClipboardHelper.cs
@@ -5,6 +5,7 @@
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
+using ManagedCommon;
using static ColorPicker.NativeMethods;
namespace ColorPicker.Helpers
diff --git a/src/modules/colorPicker/ColorPickerUI/Helpers/Logger.cs b/src/modules/colorPicker/ColorPickerUI/Helpers/Logger.cs
deleted file mode 100644
index 93116cbaa7..0000000000
--- a/src/modules/colorPicker/ColorPickerUI/Helpers/Logger.cs
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright (c) Microsoft Corporation
-// The Microsoft Corporation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using System.Diagnostics;
-using System.Globalization;
-using System.IO;
-using System.IO.Abstractions;
-using interop;
-
-namespace ColorPicker.Helpers
-{
- public static class Logger
- {
- private static readonly IFileSystem _fileSystem = new FileSystem();
- private static readonly string ApplicationLogPath = Path.Combine(Constants.AppDataPath(), "ColorPicker\\Logs");
-
- static Logger()
- {
- if (!_fileSystem.Directory.Exists(ApplicationLogPath))
- {
- _fileSystem.Directory.CreateDirectory(ApplicationLogPath);
- }
-
- // Using InvariantCulture since this is used for a log file name
- var logFilePath = _fileSystem.Path.Combine(ApplicationLogPath, "Log_" + DateTime.Now.ToString(@"yyyy-MM-dd", CultureInfo.InvariantCulture) + ".txt");
-
- Trace.Listeners.Add(new TextWriterTraceListener(logFilePath));
-
- Trace.AutoFlush = true;
- }
-
- public static void LogError(string message)
- {
- Log(message, "ERROR");
- }
-
- public static void LogError(string message, Exception ex)
- {
- Log(
- message + Environment.NewLine +
- ex?.Message + Environment.NewLine +
- "Inner exception: " + Environment.NewLine +
- ex?.InnerException?.Message + Environment.NewLine +
- "Stack trace: " + Environment.NewLine +
- ex?.StackTrace,
- "ERROR");
- }
-
- public static void LogWarning(string message)
- {
- Log(message, "WARNING");
- }
-
- public static void LogInfo(string message)
- {
- Log(message, "INFO");
- }
-
- private static void Log(string message, string type)
- {
- Trace.WriteLine(type + ": " + DateTime.Now.TimeOfDay);
- Trace.Indent();
- Trace.WriteLine(GetCallerInfo());
- Trace.WriteLine(message);
- Trace.Unindent();
- }
-
- private static string GetCallerInfo()
- {
- StackTrace stackTrace = new StackTrace();
-
- var methodName = stackTrace.GetFrame(3)?.GetMethod();
- var className = methodName?.DeclaringType.Name;
- return "[Method]: " + methodName?.Name + " [Class]: " + className;
- }
- }
-}
diff --git a/src/modules/colorPicker/ColorPickerUI/Helpers/SessionEventHelper.cs b/src/modules/colorPicker/ColorPickerUI/Helpers/SessionEventHelper.cs
index da21c094de..8a5838d265 100644
--- a/src/modules/colorPicker/ColorPickerUI/Helpers/SessionEventHelper.cs
+++ b/src/modules/colorPicker/ColorPickerUI/Helpers/SessionEventHelper.cs
@@ -4,6 +4,7 @@
using System;
using ColorPicker.Telemetry;
+using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
using Microsoft.PowerToys.Telemetry;
diff --git a/src/modules/colorPicker/ColorPickerUI/Mouse/CursorManager.cs b/src/modules/colorPicker/ColorPickerUI/Mouse/CursorManager.cs
index fbbb416b71..d8c93bf1da 100644
--- a/src/modules/colorPicker/ColorPickerUI/Mouse/CursorManager.cs
+++ b/src/modules/colorPicker/ColorPickerUI/Mouse/CursorManager.cs
@@ -4,7 +4,7 @@
using System;
using System.IO.Abstractions;
-using ColorPicker.Helpers;
+using ManagedCommon;
using Microsoft.Win32;
namespace ColorPicker.Mouse
diff --git a/src/modules/colorPicker/ColorPickerUI/Mouse/MouseHook.cs b/src/modules/colorPicker/ColorPickerUI/Mouse/MouseHook.cs
index d75e57a024..080ec9d35e 100644
--- a/src/modules/colorPicker/ColorPickerUI/Mouse/MouseHook.cs
+++ b/src/modules/colorPicker/ColorPickerUI/Mouse/MouseHook.cs
@@ -7,6 +7,7 @@ using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Input;
using ColorPicker.Helpers;
+using ManagedCommon;
using static ColorPicker.NativeMethods;
namespace ColorPicker.Mouse
diff --git a/src/modules/colorPicker/ColorPickerUI/Program.cs b/src/modules/colorPicker/ColorPickerUI/Program.cs
index 9c97e8308b..b3e502171f 100644
--- a/src/modules/colorPicker/ColorPickerUI/Program.cs
+++ b/src/modules/colorPicker/ColorPickerUI/Program.cs
@@ -6,6 +6,7 @@ using System;
using ColorPicker.Helpers;
using ColorPicker.Mouse;
using ColorPickerUI;
+using ManagedCommon;
namespace ColorPicker
{
@@ -16,6 +17,8 @@ namespace ColorPicker
[STAThread]
public static void Main(string[] args)
{
+ Logger.InitializeLogger("\\ColorPicker\\Logs");
+
_args = args;
Logger.LogInfo($"Color Picker started with pid={Environment.ProcessId}");
diff --git a/src/modules/colorPicker/ColorPickerUI/Settings/UserSettings.cs b/src/modules/colorPicker/ColorPickerUI/Settings/UserSettings.cs
index 175413865c..f7f815fd9f 100644
--- a/src/modules/colorPicker/ColorPickerUI/Settings/UserSettings.cs
+++ b/src/modules/colorPicker/ColorPickerUI/Settings/UserSettings.cs
@@ -10,6 +10,7 @@ using System.IO.Abstractions;
using System.Linq;
using System.Threading;
using ColorPicker.Common;
+using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs
index f3ee395100..faec50e2aa 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs
@@ -8,7 +8,6 @@ using System.Threading;
using System.Windows;
using System.Windows.Input;
using Common.UI;
-using FancyZonesEditor.Logs;
using FancyZonesEditor.Utils;
using ManagedCommon;
@@ -55,6 +54,8 @@ namespace FancyZonesEditor
public App()
{
+ Logger.InitializeLogger("\\FancyZones\\Editor\\Logs");
+
// DebugModeCheck();
NativeThreadCTS = new CancellationTokenSource();
FancyZonesEditorIO = new FancyZonesEditorIO();
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/CanvasEditorWindow.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/CanvasEditorWindow.xaml.cs
index d6e38930b3..2bbaa067fe 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/CanvasEditorWindow.xaml.cs
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/CanvasEditorWindow.xaml.cs
@@ -4,8 +4,8 @@
using System.Windows;
using System.Windows.Input;
-using FancyZonesEditor.Logs;
using FancyZonesEditor.Models;
+using ManagedCommon;
namespace FancyZonesEditor
{
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/EditorWindow.cs b/src/modules/fancyzones/editor/FancyZonesEditor/EditorWindow.cs
index 6bd3f3b652..4a29c81194 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/EditorWindow.cs
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/EditorWindow.cs
@@ -4,8 +4,8 @@
using System;
using System.Windows;
-using FancyZonesEditor.Logs;
using FancyZonesEditor.Models;
+using ManagedCommon;
namespace FancyZonesEditor
{
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/GridData.cs b/src/modules/fancyzones/editor/FancyZonesEditor/GridData.cs
index 749ee5a34d..b71cdecb17 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/GridData.cs
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/GridData.cs
@@ -6,8 +6,8 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;
-using FancyZonesEditor.Logs;
using FancyZonesEditor.Models;
+using ManagedCommon;
namespace FancyZonesEditor
{
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/GridEditor.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/GridEditor.xaml.cs
index 3b5af0ac1a..d49ad9232e 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/GridEditor.xaml.cs
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/GridEditor.xaml.cs
@@ -10,8 +10,8 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
-using FancyZonesEditor.Logs;
using FancyZonesEditor.Models;
+using ManagedCommon;
namespace FancyZonesEditor
{
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/LayoutPreview.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/LayoutPreview.xaml.cs
index 7cf7257522..61aad3945b 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/LayoutPreview.xaml.cs
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/LayoutPreview.xaml.cs
@@ -7,8 +7,8 @@ using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
-using FancyZonesEditor.Logs;
using FancyZonesEditor.Models;
+using ManagedCommon;
namespace FancyZonesEditor
{
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml.cs
index 9645be9f6d..687895021b 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml.cs
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml.cs
@@ -11,9 +11,9 @@ using System.Windows.Automation.Peers;
using System.Windows.Controls;
using System.Windows.Input;
using Common.UI;
-using FancyZonesEditor.Logs;
using FancyZonesEditor.Models;
using FancyZonesEditor.Utils;
+using ManagedCommon;
using ModernWpf.Controls;
namespace FancyZonesEditor
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Overlay.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Overlay.cs
index 0545ce6c55..5677fb565f 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/Overlay.cs
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/Overlay.cs
@@ -6,8 +6,8 @@ using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
-using FancyZonesEditor.Logs;
using FancyZonesEditor.Models;
+using ManagedCommon;
namespace FancyZonesEditor
{
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Utils/FancyZonesEditorIO.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Utils/FancyZonesEditorIO.cs
index 26b0dfa151..2ddf1cafaf 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/Utils/FancyZonesEditorIO.cs
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/Utils/FancyZonesEditorIO.cs
@@ -12,8 +12,8 @@ using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows;
-using FancyZonesEditor.Logs;
using FancyZonesEditor.Models;
+using ManagedCommon;
namespace FancyZonesEditor.Utils
{
diff --git a/src/modules/poweraccent/PowerAccent.Core/PowerAccent.cs b/src/modules/poweraccent/PowerAccent.Core/PowerAccent.cs
index 999620ac32..01d87d034c 100644
--- a/src/modules/poweraccent/PowerAccent.Core/PowerAccent.cs
+++ b/src/modules/poweraccent/PowerAccent.Core/PowerAccent.cs
@@ -6,6 +6,7 @@ using System.Globalization;
using System.Text;
using System.Unicode;
using System.Windows;
+using ManagedCommon;
using PowerAccent.Core.Services;
using PowerAccent.Core.Tools;
using PowerToys.PowerAccentKeyboardService;
@@ -41,6 +42,8 @@ public class PowerAccent : IDisposable
public PowerAccent()
{
+ Logger.InitializeLogger("\\QuickAccent\\Logs");
+
LoadUnicodeInfoCache();
_keyboardListener = new KeyboardListener();
diff --git a/src/modules/poweraccent/PowerAccent.Core/Services/SettingsService.cs b/src/modules/poweraccent/PowerAccent.Core/Services/SettingsService.cs
index d3d89821c9..50ba68f546 100644
--- a/src/modules/poweraccent/PowerAccent.Core/Services/SettingsService.cs
+++ b/src/modules/poweraccent/PowerAccent.Core/Services/SettingsService.cs
@@ -4,6 +4,7 @@
using System.IO.Abstractions;
using System.Text.Json;
+using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
diff --git a/src/modules/poweraccent/PowerAccent.Core/Tools/Logger.cs b/src/modules/poweraccent/PowerAccent.Core/Tools/Logger.cs
deleted file mode 100644
index f79e3a42cc..0000000000
--- a/src/modules/poweraccent/PowerAccent.Core/Tools/Logger.cs
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright (c) Microsoft Corporation
-// The Microsoft Corporation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Diagnostics;
-using System.Globalization;
-using System.IO;
-using System.IO.Abstractions;
-using interop;
-
-namespace PowerAccent.Core.Tools
-{
- public static class Logger
- {
- private static readonly IFileSystem _fileSystem = new FileSystem();
- private static readonly string ApplicationLogPath = Path.Combine(Constants.AppDataPath(), "QuickAccent\\Logs");
-
- static Logger()
- {
- if (!_fileSystem.Directory.Exists(ApplicationLogPath))
- {
- _fileSystem.Directory.CreateDirectory(ApplicationLogPath);
- }
-
- // Using InvariantCulture since this is used for a log file name
- string logFilePath = _fileSystem.Path.Combine(ApplicationLogPath, "Log_" + DateTime.Now.ToString(@"yyyy-MM-dd", CultureInfo.InvariantCulture) + ".txt");
-
- Trace.Listeners.Add(new TextWriterTraceListener(logFilePath));
-
- Trace.AutoFlush = true;
- }
-
- public static void LogError(string message)
- {
- Log(message, "ERROR");
- }
-
- public static void LogError(string message, Exception ex)
- {
- Log(
- message + Environment.NewLine +
- ex?.Message + Environment.NewLine +
- "Inner exception: " + Environment.NewLine +
- ex?.InnerException?.Message + Environment.NewLine +
- "Stack trace: " + Environment.NewLine +
- ex?.StackTrace,
- "ERROR");
- }
-
- public static void LogWarning(string message)
- {
- Log(message, "WARNING");
- }
-
- public static void LogInfo(string message)
- {
- Log(message, "INFO");
- }
-
- private static void Log(string message, string type)
- {
- Trace.WriteLine(type + ": " + DateTime.Now.TimeOfDay);
- Trace.Indent();
- Trace.WriteLine(GetCallerInfo());
- Trace.WriteLine(message);
- Trace.Unindent();
- }
-
- private static string GetCallerInfo()
- {
- StackTrace stackTrace = new StackTrace();
-
- System.Reflection.MethodBase methodName = stackTrace.GetFrame(3)?.GetMethod();
- string className = methodName?.DeclaringType?.Name;
- return "[Method]: " + methodName?.Name + " [Class]: " + className;
- }
- }
-}
diff --git a/src/modules/poweraccent/PowerAccent.UI/App.xaml.cs b/src/modules/poweraccent/PowerAccent.UI/App.xaml.cs
index e4c77b9d0b..af3ff38db9 100644
--- a/src/modules/poweraccent/PowerAccent.UI/App.xaml.cs
+++ b/src/modules/poweraccent/PowerAccent.UI/App.xaml.cs
@@ -6,6 +6,7 @@ using System;
using System.Threading;
using System.Windows;
using Common.UI;
+using ManagedCommon;
using PowerAccent.Core.Tools;
namespace PowerAccent.UI
diff --git a/src/modules/poweraccent/PowerAccent.UI/Program.cs b/src/modules/poweraccent/PowerAccent.UI/Program.cs
index eee06b2038..9ca3de95be 100644
--- a/src/modules/poweraccent/PowerAccent.UI/Program.cs
+++ b/src/modules/poweraccent/PowerAccent.UI/Program.cs
@@ -22,6 +22,8 @@ internal static class Program
[STAThread]
public static void Main(string[] args)
{
+ Logger.InitializeLogger("\\QuickAccent\\Logs");
+
if (PowerToys.GPOWrapper.GPOWrapper.GetConfiguredQuickAccentEnabledValue() == PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
{
Logger.LogWarning("Tried to start with a GPO policy setting the utility to always be disabled. Please contact your systems administrator.");
diff --git a/src/modules/previewpane/MonacoPreviewHandler/MonacoPreviewHandlerControl.cs b/src/modules/previewpane/MonacoPreviewHandler/MonacoPreviewHandlerControl.cs
index 6c8d832b2f..f4aac30d7e 100644
--- a/src/modules/previewpane/MonacoPreviewHandler/MonacoPreviewHandlerControl.cs
+++ b/src/modules/previewpane/MonacoPreviewHandler/MonacoPreviewHandlerControl.cs
@@ -12,8 +12,8 @@ using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows.Forms;
using Common;
+using ManagedCommon;
using Microsoft.PowerToys.PreviewHandler.Monaco.Formatters;
-using Microsoft.PowerToys.PreviewHandler.Monaco.Helpers;
using Microsoft.PowerToys.PreviewHandler.Monaco.Properties;
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.WinForms;
diff --git a/src/modules/previewpane/MonacoPreviewHandler/Program.cs b/src/modules/previewpane/MonacoPreviewHandler/Program.cs
index 8589b12c30..b6bcd511f8 100644
--- a/src/modules/previewpane/MonacoPreviewHandler/Program.cs
+++ b/src/modules/previewpane/MonacoPreviewHandler/Program.cs
@@ -6,6 +6,7 @@ using System.Globalization;
using System.Windows.Threading;
using Common.UI;
using interop;
+using ManagedCommon;
namespace Microsoft.PowerToys.PreviewHandler.Monaco
{
@@ -21,6 +22,8 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
[STAThread]
public static void Main(string[] args)
{
+ Logger.InitializeLogger("\\FileExplorer_localLow\\Monaco\\logs", true);
+
ApplicationConfiguration.Initialize();
if (args != null)
{
diff --git a/src/modules/previewpane/MonacoPreviewHandler/helpers/Logger.cs b/src/modules/previewpane/MonacoPreviewHandler/helpers/Logger.cs
deleted file mode 100644
index 52d8e3f1e1..0000000000
--- a/src/modules/previewpane/MonacoPreviewHandler/helpers/Logger.cs
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright (c) Microsoft Corporation
-// The Microsoft Corporation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using System.Diagnostics;
-using System.Globalization;
-using System.IO.Abstractions;
-
-namespace Microsoft.PowerToys.PreviewHandler.Monaco.Helpers
-{
- public static class Logger
- {
- private static readonly IFileSystem _fileSystem = new FileSystem();
- private static readonly string ApplicationLogPath = System.Environment.GetEnvironmentVariable("USERPROFILE") + "\\AppData\\LocalLow\\Microsoft\\PowerToys\\logs\\FileExplorer_localLow\\Monaco";
-
- static Logger()
- {
- if (!_fileSystem.Directory.Exists(ApplicationLogPath))
- {
- _fileSystem.Directory.CreateDirectory(ApplicationLogPath);
- }
-
- // Using InvariantCulture since this is used for a log file name
- var logFilePath = _fileSystem.Path.Combine(ApplicationLogPath, "Monaco-log_" + DateTime.Now.ToString(@"yyyy-MM-dd", CultureInfo.InvariantCulture) + ".txt");
-
- Trace.Listeners.Add(new TextWriterTraceListener(logFilePath));
-
- Trace.AutoFlush = true;
- }
-
- public static void LogError(string message)
- {
- Log(message, "ERROR");
- }
-
- public static void LogError(string message, Exception ex)
- {
- Log(
- message + Environment.NewLine +
- ex?.Message + Environment.NewLine +
- "Inner exception: " + Environment.NewLine +
- ex?.InnerException?.Message + Environment.NewLine +
- "Stack trace: " + Environment.NewLine +
- ex?.StackTrace,
- "ERROR");
- }
-
- public static void LogWarning(string message)
- {
- Log(message, "WARNING");
- }
-
- public static void LogInfo(string message)
- {
- Log(message, "INFO");
- }
-
- private static void Log(string message, string type)
- {
- Trace.WriteLine(type + ": " + DateTime.Now.TimeOfDay);
- Trace.Indent();
- Trace.WriteLine(GetCallerInfo());
- Trace.WriteLine(message);
- Trace.Unindent();
- }
-
- public static void LogTrace()
- {
- Log(string.Empty, "Trace");
- }
-
- private static string GetCallerInfo()
- {
- StackTrace stackTrace = new StackTrace();
-
- var methodName = stackTrace.GetFrame(3)?.GetMethod();
- var className = methodName?.DeclaringType.Name;
- return "[Method]: " + methodName?.Name + " [Class]: " + className;
- }
- }
-}
diff --git a/src/settings-ui/Settings.UI.Library/GeneralSettings.cs b/src/settings-ui/Settings.UI.Library/GeneralSettings.cs
index e59e685b76..1de3c04030 100644
--- a/src/settings-ui/Settings.UI.Library/GeneralSettings.cs
+++ b/src/settings-ui/Settings.UI.Library/GeneralSettings.cs
@@ -5,6 +5,7 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
+using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
diff --git a/src/settings-ui/Settings.UI.Library/SettingsBackupAndRestoreUtils.cs b/src/settings-ui/Settings.UI.Library/SettingsBackupAndRestoreUtils.cs
index 36bed6bf48..1b2dc81fb7 100644
--- a/src/settings-ui/Settings.UI.Library/SettingsBackupAndRestoreUtils.cs
+++ b/src/settings-ui/Settings.UI.Library/SettingsBackupAndRestoreUtils.cs
@@ -15,6 +15,7 @@ using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.RegularExpressions;
using System.Threading;
+using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
namespace Microsoft.PowerToys.Settings.UI.Library
diff --git a/src/settings-ui/Settings.UI.Library/SettingsUtils.cs b/src/settings-ui/Settings.UI.Library/SettingsUtils.cs
index e09687ff77..a77f9e2c62 100644
--- a/src/settings-ui/Settings.UI.Library/SettingsUtils.cs
+++ b/src/settings-ui/Settings.UI.Library/SettingsUtils.cs
@@ -6,8 +6,8 @@ using System;
using System.IO;
using System.IO.Abstractions;
using System.Text.Json;
+using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
-using Microsoft.PowerToys.Settings.UI.Library.Utilities;
namespace Microsoft.PowerToys.Settings.UI.Library
{
diff --git a/src/settings-ui/Settings.UI.Library/Utilities/Logger.cs b/src/settings-ui/Settings.UI.Library/Utilities/Logger.cs
deleted file mode 100644
index fbac2c88fb..0000000000
--- a/src/settings-ui/Settings.UI.Library/Utilities/Logger.cs
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright (c) Microsoft Corporation
-// The Microsoft Corporation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using System.Diagnostics;
-using System.Globalization;
-using System.IO.Abstractions;
-
-namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
-{
- public static class Logger
- {
- private static readonly IFileSystem FileSystem = new FileSystem();
- private static readonly IPath Path = FileSystem.Path;
- private static readonly IDirectory Directory = FileSystem.Directory;
-
- private static readonly string ApplicationLogPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\PowerToys\\Settings Logs");
-
- static Logger()
- {
- if (!Directory.Exists(ApplicationLogPath))
- {
- Directory.CreateDirectory(ApplicationLogPath);
- }
-
- // Using InvariantCulture since this is used for a log file name
- var logFilePath = Path.Combine(ApplicationLogPath, "Log_" + DateTime.Now.ToString(@"yyyy-MM-dd", CultureInfo.InvariantCulture) + ".txt");
-
- Trace.Listeners.Add(new TextWriterTraceListener(logFilePath));
-
- Trace.AutoFlush = true;
- }
-
- public static void LogInfo(string message)
- {
- Log(message, "INFO");
- }
-
- public static void LogError(string message)
- {
- Log(message, "ERROR");
-#if DEBUG
- Debugger.Break();
-#endif
- }
-
- public static void LogError(string message, Exception e)
- {
- Log(
- message + Environment.NewLine +
- e?.Message + Environment.NewLine +
- "Inner exception: " + Environment.NewLine +
- e?.InnerException?.Message + Environment.NewLine +
- "Stack trace: " + Environment.NewLine +
- e?.StackTrace,
- "ERROR");
-#if DEBUG
- Debugger.Break();
-#endif
- }
-
- private static void Log(string message, string type)
- {
- Trace.WriteLine(type + ": " + DateTime.Now.TimeOfDay);
- Trace.Indent();
- Trace.WriteLine(GetCallerInfo());
- Trace.WriteLine(message);
- Trace.Unindent();
- }
-
- private static string GetCallerInfo()
- {
- StackTrace stackTrace = new StackTrace();
-
- var methodName = stackTrace.GetFrame(3)?.GetMethod();
- var className = methodName?.DeclaringType.Name;
- return "[Method]: " + methodName?.Name + " [Class]: " + className;
- }
- }
-}
diff --git a/src/settings-ui/Settings.UI/App.xaml.cs b/src/settings-ui/Settings.UI/App.xaml.cs
index 14512c75e3..75cc05883e 100644
--- a/src/settings-ui/Settings.UI/App.xaml.cs
+++ b/src/settings-ui/Settings.UI/App.xaml.cs
@@ -72,6 +72,8 @@ namespace Microsoft.PowerToys.Settings.UI
///
public App()
{
+ Logger.InitializeLogger("\\Settings\\Logs");
+
this.InitializeComponent();
}
diff --git a/src/settings-ui/Settings.UI/OOBE/Views/OobeWhatsNew.xaml.cs b/src/settings-ui/Settings.UI/OOBE/Views/OobeWhatsNew.xaml.cs
index 258b8625cd..fd35eafc39 100644
--- a/src/settings-ui/Settings.UI/OOBE/Views/OobeWhatsNew.xaml.cs
+++ b/src/settings-ui/Settings.UI/OOBE/Views/OobeWhatsNew.xaml.cs
@@ -14,7 +14,7 @@ using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using CommunityToolkit.WinUI.UI.Controls;
-using Microsoft.PowerToys.Settings.UI.Library.Utilities;
+using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.OOBE.Enums;
using Microsoft.PowerToys.Settings.UI.OOBE.ViewModel;
using Microsoft.UI.Xaml.Controls;
diff --git a/src/settings-ui/Settings.UI/ViewModels/AwakeViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/AwakeViewModel.cs
index 28dd371fcc..5980e31148 100644
--- a/src/settings-ui/Settings.UI/ViewModels/AwakeViewModel.cs
+++ b/src/settings-ui/Settings.UI/ViewModels/AwakeViewModel.cs
@@ -4,6 +4,7 @@
using System;
using System.Runtime.CompilerServices;
+using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
diff --git a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs
index db3ac314e2..874c20722a 100644
--- a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs
+++ b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs
@@ -13,6 +13,7 @@ using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Threading.Tasks;
using global::PowerToys.GPOWrapper;
+using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
diff --git a/src/settings-ui/Settings.UI/ViewModels/ImageResizerViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/ImageResizerViewModel.cs
index ed9432c0c5..ad7ba3c679 100644
--- a/src/settings-ui/Settings.UI/ViewModels/ImageResizerViewModel.cs
+++ b/src/settings-ui/Settings.UI/ViewModels/ImageResizerViewModel.cs
@@ -8,10 +8,10 @@ using System.ComponentModel;
using System.IO;
using System.Linq;
using global::PowerToys.GPOWrapper;
+using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
-using Microsoft.PowerToys.Settings.UI.Library.Utilities;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
diff --git a/src/settings-ui/Settings.UI/ViewModels/KeyboardManagerViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/KeyboardManagerViewModel.cs
index a12e5cfdfb..771ac564d7 100644
--- a/src/settings-ui/Settings.UI/ViewModels/KeyboardManagerViewModel.cs
+++ b/src/settings-ui/Settings.UI/ViewModels/KeyboardManagerViewModel.cs
@@ -12,10 +12,10 @@ using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using global::PowerToys.GPOWrapper;
+using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
-using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
using Microsoft.PowerToys.Settings.Utilities;
using Windows.ApplicationModel.Resources;
diff --git a/src/settings-ui/Settings.UI/ViewModels/PowerRenameViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/PowerRenameViewModel.cs
index 039ee3e410..1f1b42635b 100644
--- a/src/settings-ui/Settings.UI/ViewModels/PowerRenameViewModel.cs
+++ b/src/settings-ui/Settings.UI/ViewModels/PowerRenameViewModel.cs
@@ -6,10 +6,10 @@ using System;
using System.IO;
using System.Runtime.CompilerServices;
using global::PowerToys.GPOWrapper;
+using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
-using Microsoft.PowerToys.Settings.UI.Library.Utilities;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
diff --git a/src/settings-ui/Settings.UI/Views/AwakePage.xaml.cs b/src/settings-ui/Settings.UI/Views/AwakePage.xaml.cs
index 35dccfbb50..2079c73eae 100644
--- a/src/settings-ui/Settings.UI/Views/AwakePage.xaml.cs
+++ b/src/settings-ui/Settings.UI/Views/AwakePage.xaml.cs
@@ -5,10 +5,10 @@
using System;
using System.IO;
using System.IO.Abstractions;
+using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
-using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml.Controls;
diff --git a/src/settings-ui/Settings.UI/Views/GeneralPage.xaml.cs b/src/settings-ui/Settings.UI/Views/GeneralPage.xaml.cs
index 3a3a68ca11..92c3fd7da1 100644
--- a/src/settings-ui/Settings.UI/Views/GeneralPage.xaml.cs
+++ b/src/settings-ui/Settings.UI/Views/GeneralPage.xaml.cs
@@ -3,17 +3,15 @@
// See the LICENSE file in the project root for more information.
using System;
-using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
+using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
-using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Windows.ApplicationModel.Resources;
-using Windows.Storage;
using Windows.Storage.Pickers;
namespace Microsoft.PowerToys.Settings.UI.Views
diff --git a/src/settings-ui/Settings.UI/Views/ImageResizerPage.xaml.cs b/src/settings-ui/Settings.UI/Views/ImageResizerPage.xaml.cs
index 6e47db0455..2f6de716ef 100644
--- a/src/settings-ui/Settings.UI/Views/ImageResizerPage.xaml.cs
+++ b/src/settings-ui/Settings.UI/Views/ImageResizerPage.xaml.cs
@@ -4,9 +4,9 @@
using System;
using System.Globalization;
+using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
-using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
diff --git a/src/settings-ui/Settings.UI/Views/PowerLauncherPage.xaml.cs b/src/settings-ui/Settings.UI/Views/PowerLauncherPage.xaml.cs
index 01a79283f8..dcec402c51 100644
--- a/src/settings-ui/Settings.UI/Views/PowerLauncherPage.xaml.cs
+++ b/src/settings-ui/Settings.UI/Views/PowerLauncherPage.xaml.cs
@@ -5,9 +5,9 @@
using System;
using System.Collections.ObjectModel;
using System.IO;
+using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
-using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Microsoft.UI.Xaml.Controls;