How to use NLog in ASP.NET

When you want to use NLog in ASP.NET, the first step is to install and configure NLog. Then you can either use it directly or fully integrate it and ASP.NET. Use NLog directly if you prefer to have static ILogger properties, instead of using dependency injection. The downside of this approach is that you’ll have … Read more

NLog – Log to console

There are two configuration options for logging to the console when you’re using NLog: In this article, I’ll show how to configure these two targets using nlog.config. At the end, I’ll show an example of configuring NLog programmatically. Console target Add a Console target and a rule that writes to that target in nlog.config, like … Read more

NLog – Archive by file size

To archive by file size when you’re using NLog, you can configure nlog.config like this: You specify archiveAboveSize in bytes. The above configuration is specifying ~1 MB. When your log file hits the specified size, NLog will “archive” the file, which really just means it will rename the log file and start a new log … Read more

NLog – Split trace logging into its own file

This article explains how to configure NLog so that trace-level log messages go to their own file. This is useful because trace logging involves logging every method call for short-term troubleshooting, leading to very large log files. This approach only requires modifying the nlog.config file, and doesn’t require any code changes. In the end, all … Read more