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
7 changes: 5 additions & 2 deletions src/Applications/ACATApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using ACAT.Extension;
using ACAT.Extension.CommandHandlers;
using ACATResources;
using Microsoft.Extensions.Logging;
using System;
using System.Windows.Forms;
using System.Windows.Navigation;
Expand All @@ -36,6 +37,7 @@ internal static class Program
{
private static Splash splash = null;
private static Microsoft.Extensions.Logging.ILoggerFactory modernLoggingFactory = null;
private static ILogger _logger;

/// <summary>
/// The main entry point for the application.
Expand Down Expand Up @@ -102,8 +104,9 @@ private static void InitializeLogging()

// Initialize modern logging infrastructure (ticket #3)
modernLoggingFactory = LoggingConfiguration.CreateLoggerFactory();
_logger = modernLoggingFactory.CreateLogger(typeof(Program));

Log.Debug("ACAT Dashboard Application Launch");
_logger.LogDebug("ACAT Dashboard Application Launch");
}

private static void InitializeUser()
Expand Down Expand Up @@ -210,7 +213,7 @@ private static void ShutdownApplication()
Context.Dispose();
Common.Uninit();
CloseSplashScreen();
Log.Debug("ACATTalk Application shutdown");
_logger.LogDebug("ACATTalk Application shutdown");
Log.Close();
modernLoggingFactory?.Dispose();
AppCommon.OnExit();
Expand Down
11 changes: 7 additions & 4 deletions src/Applications/ACATConfigNext/Forms/SettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using ACAT.Core.WidgetManagement;
using ACAT.Extension;
using ACATConfigNext.UserControls;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand All @@ -18,6 +19,7 @@ namespace ACATConfigNext.Forms
{
public class SettingsForm : Form
{
private readonly ILogger<SettingsForm> _logger;
private TableLayoutPanel basePanel;
private FlowLayoutPanel leftPanel;
private TableLayoutPanel navPanel;
Expand All @@ -40,8 +42,9 @@ public class SettingsForm : Form

private bool _isDirty = false;

public SettingsForm()
public SettingsForm(ILogger<SettingsForm> logger)
{
_logger = logger;
WpfInitializationHelper.EnsureApplicationResources();

InitializeComponent();
Expand Down Expand Up @@ -183,7 +186,7 @@ private void ButtonClicked_Cancel(object sender, EventArgs e)
}
catch (Exception ex)
{
Log.Exception(ex);
_logger.LogError(ex, "An error occurred while canceling changes");
MessageBox.Show("An error occurred while canceling changes.", "Cancel Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Expand Down Expand Up @@ -215,7 +218,7 @@ private void ButtonClicked_Exit(object sender, EventArgs e)
}
catch (Exception ex)
{
Log.Exception(ex);
_logger.LogError(ex, "An error occurred while exiting");
MessageBox.Show("An error occurred while saving settings.", "Save Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Expand Down Expand Up @@ -401,7 +404,7 @@ private void CopyPreferencesValues(IPreferences source, IPreferences target)
}
catch (Exception ex)
{
Log.Debug($"Could not copy property {prop.Name}: {ex.Message}");
_logger.LogDebug("Could not copy property {PropertyName}: {Message}", prop.Name, ex.Message);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ACAT.Core.Utility;
using ACAT.Core.Extensions;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Drawing;
Expand All @@ -18,9 +19,11 @@ namespace ACATConfigNext.UserControls
{
internal class GroupedSettingsPanel : UserControl
{
private readonly ILogger<GroupedSettingsPanel> _logger;
private TableLayoutPanel basePanel;
public GroupedSettingsPanel(Action<UserControl, string> showPanel, IEnumerable<IExtension> acat_extensions, PropertyChangedEventHandler settingsChangedHandler)
public GroupedSettingsPanel(Action<UserControl, string> showPanel, IEnumerable<IExtension> acat_extensions, PropertyChangedEventHandler settingsChangedHandler, ILogger<GroupedSettingsPanel> logger = null)
{
_logger = logger;
basePanel = new TableLayoutPanel()
{
BackColor = Color.Transparent,
Expand Down Expand Up @@ -153,7 +156,8 @@ private static void AddPanelClickEvent(Control control, Action<UserControl, stri
{
control.Click += (s, e) =>
{
Log.Debug("Clicked on control: " + control.Name);
var logger = LoggingConfiguration.CreateLogger<GroupedSettingsPanel>();
logger.LogDebug("Clicked on control: {ControlName}", control.Name);
Control clickedControl = s as Control;

while (clickedControl != null && clickedControl is not TableLayoutPanel)
Expand All @@ -166,7 +170,7 @@ private static void AddPanelClickEvent(Control control, Action<UserControl, stri
var extension = panel.Tag as IExtension;
if (extension != null)
{
Log.Debug("Showing acat_extensions for: " + extension.Descriptor.Name);
logger.LogDebug("Showing acat_extensions for: {ExtensionName}", extension.Descriptor.Name);
MethodInfo method = extension.GetType().GetMethod("GetPreferences");

var prefs = method?.Invoke(extension, null) as PreferencesBase;
Expand All @@ -179,12 +183,12 @@ private static void AddPanelClickEvent(Control control, Action<UserControl, stri
method = extension.GetType().GetMethod("ShowPreferencesDialog");
if (method != null)
{
Log.Debug("Showing preferences dialog for: " + extension.Descriptor.Name);
logger.LogDebug("Showing preferences dialog for: {ExtensionName}", extension.Descriptor.Name);
method.Invoke(extension, null);
}
else
{
Log.Error("No preferences method found for extension: " + extension.Descriptor.Name);
logger.LogError("No preferences method found for extension: {ExtensionName}", extension.Descriptor.Name);
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/Applications/ACATTalk/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using ACAT.Extension;
using ACAT.Extension.CommandHandlers;
using ACATResources;
using Microsoft.Extensions.Logging;
using System;
using System.Windows.Forms;

Expand All @@ -33,6 +34,7 @@ namespace ACATTalk
internal static class Program
{
private static Splash splash = null;
private static ILogger _logger;

/// <summary>
/// The main entry point for the application.
Expand Down Expand Up @@ -91,8 +93,9 @@ public static void Main(string[] args)

// Initialize modern logging infrastructure (ticket #3)
var modernLoggingFactory = LoggingConfiguration.CreateLoggerFactory();
_logger = modernLoggingFactory.CreateLogger(typeof(Program));

Log.Debug("ACAT Talk Application Launch");
_logger.LogDebug("ACAT Talk Application Launch");

AuditLog.Audit(new AuditEvent("Application", "start"));

Expand Down Expand Up @@ -194,7 +197,7 @@ public static void Main(string[] args)
splash?.Close();
splash = null;

Log.Debug("ACATTalk Application shutdown");
_logger.LogDebug("ACATTalk Application shutdown");

Log.Close();
modernLoggingFactory?.Dispose();
Expand Down
41 changes: 22 additions & 19 deletions src/Applications/ACATWatch/ACATWatchForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

using ACAT.Core.Utility;
using ACAT.Core.Utility.NamedPipe;
using Microsoft.Extensions.Logging;
using System;
using System.ComponentModel;
using System.Diagnostics;
Expand All @@ -31,12 +32,14 @@ public partial class ACATWatchForm : Form
{
private static readonly int ASFW_ANY = -1;
private static readonly uint LSFW_UNLOCK = 2;
private readonly ILogger<ACATWatchForm> _logger;
private PipeServer _pipeServer;
private NotifyIcon trayIcon;
private readonly ContextMenu trayMenu;

public ACATWatchForm()
public ACATWatchForm(ILogger<ACATWatchForm> logger)
{
_logger = logger;
InitializeComponent();

Application.ApplicationExit += Application_ApplicationExit;
Expand Down Expand Up @@ -1294,9 +1297,9 @@ public static void ForceWindowIntoForeground(IntPtr window)
AllowSetForegroundWindow(ASFW_ANY);

User32Interop.SetForegroundWindow(window);
Log.Debug("Calling BringWindowToTop");
_logger.LogDebug("Calling BringWindowToTop");
User32Interop.BringWindowToTop(window);
Log.Debug("Calling ShowWindow");
_logger.LogDebug("Calling ShowWindow");
User32Interop.ShowWindow(window.ToInt32(), User32Interop.SW_SHOW);

SystemParametersInfo(SPI.SPI_SETFOREGROUNDLOCKTIMEOUT, 0, ref oldTimeout, 0);
Expand All @@ -1311,36 +1314,36 @@ public void FocusWindow(IntPtr focusOnWindowHandle)
{
User32Interop.GetWindowLong(focusOnWindowHandle, User32Interop.GWL_STYLE);
IntPtr fg = User32Interop.GetForegroundWindow();
Log.Debug("Fg window handle: " + fg.ToInt32());
_logger.LogDebug("Fg window handle: " + fg.ToInt32());

User32Interop.GetWindowThreadProcessId(User32Interop.GetForegroundWindow(), out uint h);

Log.Debug("Process id of fgwindow: " + h);
_logger.LogDebug("Process id of fgwindow: " + h);
uint currentlyFocusedWindowProcessIdThread = User32Interop.GetWindowThreadProcessId(focusOnWindowHandle, out h);

Log.Debug("Process id of focusOnWindowHandle: " + h);
_logger.LogDebug("Process id of focusOnWindowHandle: " + h);

uint appThread = Kernel32Interop.GetCurrentThreadId();

Log.Debug("appthread: " + appThread);
_logger.LogDebug("appthread: " + appThread);

if (currentlyFocusedWindowProcessIdThread != appThread)
{
Log.Debug("currentlyFocusedWindowProcessId != appThread");
_logger.LogDebug("currentlyFocusedWindowProcessId != appThread");
bool ret = User32Interop.AttachThreadInput(currentlyFocusedWindowProcessIdThread, appThread, true);
Log.Debug("AttachThreaInput returned " + ret);
Log.Debug("Calling BringWindowToTop");
_logger.LogDebug("AttachThreaInput returned " + ret);
_logger.LogDebug("Calling BringWindowToTop");
User32Interop.BringWindowToTop(focusOnWindowHandle);
Log.Debug("Calling ShowWindow");
_logger.LogDebug("Calling ShowWindow");
User32Interop.ShowWindow(focusOnWindowHandle.ToInt32(), User32Interop.SW_SHOW);
User32Interop.AttachThreadInput(currentlyFocusedWindowProcessIdThread, appThread, false);
}
else
{
Log.Debug("Calling BringWindowToTop");
_logger.LogDebug("Calling BringWindowToTop");

User32Interop.BringWindowToTop(focusOnWindowHandle);
Log.Debug("Calling ShowWindow");
_logger.LogDebug("Calling ShowWindow");

User32Interop.ShowWindow(focusOnWindowHandle.ToInt32(), User32Interop.SW_SHOW);
}
Expand Down Expand Up @@ -1369,9 +1372,9 @@ private void _pipeServer_MessageReceived(object sender, MessageReceivedEventArgs
return;
}

Log.Debug("Set focus to " + e.Message);
_logger.LogDebug("Set focus to " + e.Message);
int h = Int32.Parse(e.Message);
Log.Debug("h: " + h);
_logger.LogDebug("h: " + h);
if (h != 0)
{
IntPtr handle = new(h);
Expand Down Expand Up @@ -1428,7 +1431,7 @@ private void dispose()

private void LauncherForm_FormClosing(object sender, FormClosingEventArgs e)
{
Log.Debug("Closing ACATWatchForm");
_logger.LogDebug("Closing ACATWatchForm");
dispose();
}

Expand All @@ -1440,15 +1443,15 @@ private void LauncherForm_Load(object sender, EventArgs e)

_pipeServer = new PipeServer("ACATWatch", PipeDirection.InOut);
_pipeServer.MessageReceived += _pipeServer_MessageReceived;
Log.Debug("Starting pipe server");
_logger.LogDebug("Starting pipe server");

try
{
_pipeServer.Start();
}
catch (Exception ex)
{
Log.Exception("Failed to start pipe server", ex);
_logger.LogError(ex, "Failed to start pipe server");
}
}

Expand Down Expand Up @@ -1490,7 +1493,7 @@ private void PipesMessageHandler(string message)
}
catch (Exception ex)
{
Log.Exception(ex);
_logger.LogError(ex, "Error in PipesMessageHandler");
}
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/Applications/ACATWatch/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using ACAT.Applications.ACATWatch;
using ACAT.Core.Utility;
using ACAT.Extension;
using Microsoft.Extensions.Logging;
using System;
using System.Reflection;
using System.Windows.Forms;
Expand All @@ -22,6 +23,8 @@ namespace ACATWatch
{
internal static class Program
{
private static ILogger _logger;

/// <summary>
/// The main entry point for the application.
/// </summary>
Expand All @@ -46,23 +49,27 @@ private static void Main()

// Initialize modern logging infrastructure (ticket #3)
var modernLogger = LoggingConfiguration.CreateLoggerFactory();
_logger = modernLogger.CreateLogger(typeof(Program));

FileUtils.LogAssemblyInfo(Assembly.GetExecutingAssembly());

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new ACATWatchForm());
Application.Run(new ACATWatchForm(_logger));

Log.Info("**** Exit " + Common.AppPreferences.AppName + " " + DateTime.Now.ToString() + " ****");
_logger.LogInformation("**** Exit " + Common.AppPreferences.AppName + " " + DateTime.Now.ToString() + " ****");

Log.Close();
modernLogger?.Dispose();
}
else
{
Log.SetupListeners();
Log.Error("Failed to load user preferences. Exiting application.");
var tempFactory = LoggingConfiguration.CreateLoggerFactory();
var tempLogger = tempFactory.CreateLogger(typeof(Program));
tempLogger.LogError("Failed to load user preferences. Exiting application.");
Log.Close();
tempFactory.Dispose();
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/Applications/AppCommon/Onboarding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using ACAT.Extension;
using ACAT.Extensions.Onboarding.UI;
using ACAT.Extensions.Onboarding.UI.Forms;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Reflection;
Expand Down Expand Up @@ -49,6 +50,7 @@ public static bool DoOnboarding()

public static bool ResetAllPreferences(List<PreferencesCategory> currentCategory)
{
var logger = LoggingConfiguration.CreateLogger(typeof(AppCommon));
try
{
// Reset general preferences
Expand Down Expand Up @@ -82,13 +84,14 @@ public static bool ResetAllPreferences(List<PreferencesCategory> currentCategory
}
catch (Exception ex)
{
Log.Exception(ex);
logger.LogError(ex, "Error resetting preferences");
return false;
}
}

private static void CopyPreferencesValues(IPreferences source, IPreferences target)
{
var logger = LoggingConfiguration.CreateLogger(typeof(AppCommon));
var sourceType = source.GetType();
var targetType = target.GetType();

Expand All @@ -110,7 +113,7 @@ private static void CopyPreferencesValues(IPreferences source, IPreferences targ
}
catch (Exception ex)
{
Log.Debug($"Could not copy property {prop.Name}: {ex.Message}");
logger.LogDebug("Could not copy property {PropertyName}: {Message}", prop.Name, ex.Message);
}
}
}
Expand Down
Loading
Loading