Вот рабочее решение: набор методов расширения, завернуть NLog ILogger.Error(..)
метод и любит, глядя вверх по стеку для NUnit [Test]
или [TestCase]
Атрибуты
public static void XError(this ILogger log, String message)
{
if (log.IsErrorEnabled == false)
return;
var prefix = GetCallerTestDescription();
log.Error("[{0}] {1}", prefix, message);
}
private static string GetCallerTestDescription()
{
var stack = new StackTrace(false).GetFrames();
if (stack != null)
{
foreach (var frame in stack)
{
var method = frame.GetMethod();
var testAttributes = method.GetCustomAttributes<TestAttribute>();
if (testAttributes != null && testAttributes.Any())
{
return method.Name;
}
var tcAttributes = method.GetCustomAttributes<TestCaseAttribute>();
if (tcAttributes != null && tcAttributes.Any())
{
return method.Name;
}
}
}