NLog: Log.LogTrace does not write to log target.
Type : Bug NLog version: 4.5.0-beta08 Platform: NET Core 2.0 Problem:: Log.LogTrace( … does not write to log target. Expected: Log.LogTrace logs also into the log target. Other information:
- Did you checked the Internal log? Yes
- Are there any work arrounds? No using logTrace
- Is there a version in which it did worked? I don’t know
- Can you help us by writing an unit test? No, or I can trie in the case I found where
Details: Current NLog config
<logger name="*.RestProtocol.*" writeTo="file" levels="Trace,Debug,Info,Warn" />
We like to have the logger in each Controller. As a result we created a baseController like this.
public class MyControllerBase : Controller
{
protected ILogger Log { get; set; }
protected MyControllerBase(ILoggerFactory logger)
{
Log = logger.CreateLogger(GetType().FullName);
}
}
We are using the baseController like this (here with some test logs):
[Route("api/zip")]
public class ValuesController : MyControllerBase
{
public ValuesController(ILoggerFactory loggerFactory ) : base(loggerFactory)
{
}
// GET api/values
[HttpGet]
public IEnumerable<string> Get()
{
Log.LogTrace("--------- MyTrace", null); // <-- Will never be in logfile. The others are inside the logfile.
Log.LogDebug("--------- MyDebug");
Log.LogInformation("--------- MyInfo");
Log.LogWarning("---¨!------ MyWarning");
return new string[] { "value1", "value2" };
}
}
Startup:
public class Program
{
#region Methods
public static IWebHost BuildWebHost(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.UseNLog()
.UseStartup<Startup>() // use NLog for DI Logger
.Build();
}
public static void Main(string[] args)
{
NLog.Logger logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
try
{
logger.Debug("Create Webhost");
BuildWebHost(args).Run();
}
catch (Exception e)
{
logger.Error(e, "Stopped program because of exception");
throw;
}
}
#endregion
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 22 (12 by maintainers)
@stjephan Maybe my rant at https://github.com/NLog/NLog.Web/issues/234 might be useful. Seems asp.net core 2 will choose appsettings.json LogLevel-config when available.