Skip to content

Commit a439cea

Browse files
committed
Add more logging
1 parent f4e2c5d commit a439cea

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/InEngine.Core/AbstractCommand.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
using System;
22
using System.Linq;
33
using System.Threading.Tasks;
4-
using CommandLine;
5-
using CommandLine.Text;
4+
using Common.Logging;
65
using InEngine.Core.Exceptions;
76
using InEngine.Core.IO;
87
using InEngine.Core.LifeCycle;
@@ -13,6 +12,7 @@ namespace InEngine.Core
1312
{
1413
abstract public class AbstractCommand : IJob, IWrite, IHasCommandLifeCycle
1514
{
15+
protected ILog Log { get; set; }
1616
public CommandLifeCycle CommandLifeCycle { get; set; }
1717
public Write Write { get; set; }
1818
public ProgressBar ProgressBar { get; internal set; }
@@ -23,6 +23,7 @@ abstract public class AbstractCommand : IJob, IWrite, IHasCommandLifeCycle
2323

2424
protected AbstractCommand()
2525
{
26+
Log = LogManager.GetLogger(GetType());
2627
ScheduleId = Guid.NewGuid().ToString();
2728
Name = GetType().FullName;
2829
SchedulerGroup = GetType().AssemblyQualifiedName;
@@ -53,6 +54,7 @@ public virtual void RunWithLifeCycle()
5354
}
5455
catch (Exception exception)
5556
{
57+
Log.Error(this, exception);
5658
Failed(exception);
5759
throw new CommandFailedException("Command failed. See inner exception for details.", exception);
5860
}

src/InEngine.Core/PluginAssembly.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
using System.Reflection;
66
using System.Threading;
77
using CommandLine;
8+
using Common.Logging;
89
using InEngine.Core.Exceptions;
910

1011
namespace InEngine.Core
1112
{
1213
public class PluginAssembly
1314
{
15+
ILog Log { get; set; } = LogManager.GetLogger<PluginAssembly>();
16+
1417
public Assembly Assembly { get; set; }
1518
public string Name { get { return Assembly.GetName().Name; } }
1619
public string Version { get { return Assembly.GetName().Version.ToString(); } }
@@ -34,6 +37,7 @@ public static PluginAssembly LoadFrom(string pluginName)
3437
}
3538
catch (Exception exception)
3639
{
40+
LogManager.GetLogger<PluginAssembly>().Error(exception);
3741
throw new PluginNotFoundException($"Plugin not found at {path}", exception);
3842
}
3943
}
@@ -50,6 +54,7 @@ public static List<PluginAssembly> Load<T>(bool shouldLoadCorePlugin = true) whe
5054
}
5155
catch (Exception exception)
5256
{
57+
LogManager.GetLogger<PluginAssembly>().Error(exception);
5358
throw new PluginNotFoundException("Could not load InEngine.Core plugin.", exception);
5459
}
5560

src/InEngine/ArgumentInterpreter.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using CommandLine;
5+
using Common.Logging;
46
using InEngine.Core;
57
using InEngine.Core.Exceptions;
6-
using NLog;
78
using InEngine.Core.IO;
8-
using System.Collections.Generic;
99

1010
namespace InEngine
1111
{
1212
public class ArgumentInterpreter
1313
{
14-
public Logger Logger { get; set; }
14+
public ILog Log { get; set; } = LogManager.GetLogger<PluginAssembly>();
1515
public string CliLogo { get; set; }
1616
public IWrite Write { get; set; } = new Write();
1717

1818
public ArgumentInterpreter()
1919
{
20-
Logger = LogManager.GetCurrentClassLogger();
2120
CliLogo = @"
2221
___ _____ _ _ _ _____ _____
2322
|_ _|_ __ | ____|_ __ __ _(_)_ __ ___ | \ | | ____|_ _|
@@ -80,21 +79,21 @@ public void ExitWithSuccess(string message = null)
8079
{
8180
if (string.IsNullOrWhiteSpace(message))
8281
message = "success";
83-
Logger.Debug($"✔ {message}");
82+
Log.Debug($"✔ {message}");
8483
Environment.Exit(ExitCodes.success);
8584
}
8685

8786
public void ExitWithFailure(string message = null)
8887
{
89-
Logger.Error(MakeErrorMessage(message));
88+
Log.Error(MakeErrorMessage(message));
9089
Write.Error(message);
9190
Environment.Exit(ExitCodes.fail);
9291
}
9392

9493
public void ExitWithFailure(Exception exception = null)
9594
{
9695
var ex = exception ?? new Exception("Unspecified failure");
97-
Logger.Error(ex, MakeErrorMessage(ex.Message));
96+
Log.Error(MakeErrorMessage(ex.Message), ex);
9897
Write.Error(ex.Message);
9998
Environment.Exit(ExitCodes.fail);
10099
}

0 commit comments

Comments
 (0)