[v4.0.3.13]
I notice prefix "nCrunch.TaskRunner.DotNetCore.20.x64 Information: 0 : " below when I log information log entries to trace (but not e.g. debug level), is this something NCrunch adds?
Quote:
nCrunch.TaskRunner.DotNetCore.20.x64 Information: 0 : [TEST-16:18:26.5436]|INFO|.AppPackageServiceTests.NLogTest|Test logger
Complete test code:
Quote:
[TestFixture]
internal class NLogTest
{
[Test]
public void CanUseDifferentAppAndTestInstanceLoggers()
{
void RegisterLogging(ServiceCollection services, string prefix)
{
services.AddLogging(loggingBuilder =>
{
Console.WriteLine("Configuring logging.");
loggingBuilder.ClearProviders();
loggingBuilder.SetMinimumLevel(LogLevel.Trace);
var config = new LoggingConfiguration();
//Enables us to use e.g. ThrowOnLogLevelScope helpers and such.
config.LogFactory.ThrowExceptions = true;
var logTrace = new TraceTarget("logTrace")
{
Layout =
"[" + prefix +
"-${time}]|${level:uppercase=true}|${logger:padding=32:fixedLength=true:alignmentOnTruncation=right}|${message}"
};
// Rules for mapping loggers to targets
config.AddRule(NLog.LogLevel.Trace, NLog.LogLevel.Fatal, logTrace);
loggingBuilder.AddNLog(config);
});
}
var appServices = new ServiceCollection();
var testServices = new ServiceCollection();
RegisterLogging(appServices, "APP");
RegisterLogging(testServices, "TEST");
var appProvider = appServices.BuildServiceProvider();
var testProvider = testServices.BuildServiceProvider();
var logtest = testProvider.GetRequiredService<ILogger<NLogTest>>();
logtest.LogInformation("Test logger");
var logApp = appProvider.GetRequiredService<ILogger<NLogTest>>();
logApp.LogInformation("App logger");
}
}
Thanks