NLog configuration in appsettings.json instead of nlog.config in .NET Core

Yes, this is possible but has a minimum version requirement. You must be using NLog.Extensions.Logging >= 1.5.0. Note that for ASP.NET Core applications this will be installed as a dependency if you install NLog.Web.AspNetCore >= 4.8.2. You can then create an NLog section in appsettings.json and load it with the following code: var config = … Read more

How do I configure NLog to write to a database?

You seem to be missing the parameters that are to be inserted. See the examples at http://justinpdavis.blogspot.com/2010/04/logging-to-database-with-nlog.html The nLog web page doesn’t make it very clear that these are required, but if you squint your eyes and read https://github.com/nlog/NLog/wiki/Database-target you should find that they are required.

How to configure NLog to only log from a certain level for a logger namespace for *all* targets

The solution is: <logger name=”Component.*” maxlevel=”Info” final=”true” /> You basically say, for logger(s) X, I want to skip all log entries that match Info or lower as this does not have the writeTo attribute. It is documented here: https://github.com/nlog/NLog/wiki/Configuration-file With the sample: <logger name=”Name.Space.*” minlevel=”Debug” maxlevel=”Error” final=”true” />

Add / remove logfiles during runtime in NLog

The second post on this thread led me to the solution: http://nlog-project.org/forum.html#nabble-td1685349 You have to get the current NLog configuration, make changes to this LoggingConfiguration object, then assign it back to LogManager.Configuration. This is the code I used: LoggingConfiguration config = LogManager.Configuration; var logFile = new FileTarget(); config.AddTarget(“file”, logFile); logFile.FileName = fileName + “.log”; logFile.Layout … Read more

Why won’t my windows service write to my log file?

I’ve had this issue too. As mentioned by genki you are probably logging into the \Windows\System32 directory. Maybe check for the log file you are expecting there first. When writing services I’ve often put a line like this in the beginning to get the current directory to behave like a normal application Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

Which is the best viewer for NLog? [closed]

Although a very old question, the same question has been haunting me this last couple of weeks. Here is my little contribution to the hive-mind: I found that for a lightweight client or client/server application using a simplistic, lightweight log viewer like log2console with NLogViewer target’ filled with additional parameters fields made it both easy … Read more

tech