Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Jul 23, 2024
2 parents 3a8d2ae + a541e12 commit 8b79c3d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/OneWare.Core/Services/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ public void Log(object message, ConsoleColor color = default, bool writeOutput =
public void Error(string message, Exception? exception = null, bool showOutput = true,
bool showDialog = false, Window? dialogOwner = null)
{
Log(message + "\n" + exception, ConsoleColor.Red);
var output = message + (exception != null ? $"\n{exception}" : "");
Log(output, ConsoleColor.Red);

if (showOutput && ContainerLocator.Container.IsRegistered<IOutputService>())
Dispatcher.UIThread.Post(() =>
{
ContainerLocator.Current.Resolve<IOutputService>().WriteLine("[Error]: " + message, Brushes.Red);
ContainerLocator.Current.Resolve<IOutputService>().WriteLine(output, Brushes.Red);
ContainerLocator.Current.Resolve<IDockService>()
.Show(ContainerLocator.Current.Resolve<IOutputService>());
});
Expand All @@ -73,24 +74,25 @@ public void Error(string message, Exception? exception = null, bool showOutput =
Dispatcher.UIThread.Post(() =>
{
_ = ContainerLocator.Current.Resolve<IWindowService>()
.ShowMessageAsync("Error", message, MessageBoxIcon.Error, dialogOwner);
.ShowMessageAsync("Error", output, MessageBoxIcon.Error, dialogOwner);
});
}

public void Warning(string message, Exception? exception = null, bool showOutput = true,
bool showDialog = false, Window? dialogOwner = null)
{
Log(message + "\n" + exception, ConsoleColor.Yellow);
var output = message + (exception != null ? $"\n{exception}" : "");
Log(output, ConsoleColor.Yellow);

if (showOutput && ContainerLocator.Container.IsRegistered<IOutputService>())
{
ContainerLocator.Current.Resolve<IOutputService>().WriteLine("[Warning]: " + message, Brushes.Orange);
ContainerLocator.Current.Resolve<IOutputService>().WriteLine(output, Brushes.Orange);
ContainerLocator.Current.Resolve<IDockService>().Show(ContainerLocator.Current.Resolve<IOutputService>());
}

if (showDialog)
_ = ContainerLocator.Current.Resolve<IWindowService>()
.ShowMessageAsync("Warning", message, MessageBoxIcon.Warning, dialogOwner);
.ShowMessageAsync("Warning", output, MessageBoxIcon.Warning, dialogOwner);
}

private void Init()
Expand Down

0 comments on commit 8b79c3d

Please sign in to comment.