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
4 changes: 2 additions & 2 deletions src/Stratis.Bitcoin/Configuration/Logging/ILogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public class Logger : ILogger
{
private NLog.Logger logger;

public Logger(NLog.Logger logger)
public Logger(NLog.Logger logger = null)
{
this.logger = logger;
this.logger = logger ?? NLog.LogManager.GetCurrentClassLogger();
}

/// <inheritdoc />
Expand Down
21 changes: 18 additions & 3 deletions src/Stratis.Bitcoin/Configuration/Logging/LogManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
using System.Reflection;
using Microsoft.Extensions.Logging;

namespace Stratis.Bitcoin.Configuration.Logging
Expand All @@ -24,8 +26,21 @@ private static void LogManager_ConfigurationReloaded(object sender, NLog.Config.

public static ILogger GetCurrentClassLogger()
{
var methodInfo = new StackTrace().GetFrame(1).GetMethod();
return new Logger(NLog.LogManager.GetLogger(methodInfo.ReflectedType.ToString()));
try
{
var stackTrace = new StackTrace();
if (stackTrace.FrameCount > 1)
{

MethodBase methodInfo = stackTrace.GetFrame(1).GetMethod();
return new Logger(NLog.LogManager.GetLogger(methodInfo.ReflectedType.ToString()));
}
}
catch (Exception)
{
}

return new Logger();
}

public static void ReconfigExistingLoggers()
Expand Down
6 changes: 0 additions & 6 deletions src/Stratis.Bitcoin/Configuration/Logging/LoggerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ namespace Stratis.Bitcoin.Configuration.Logging
{
public class CustomLoggerFactory : ILoggerFactory
{
public ILogger CreateLogger()
{
var methodInfo = new StackTrace().GetFrame(1).GetMethod();
return new Logger(NLog.LogManager.LogFactory.GetLogger(methodInfo.ReflectedType.ToString()));
}

public ILogger CreateLogger(string name)
{
return new Logger(NLog.LogManager.LogFactory.GetLogger(name));
Expand Down