CampusNexus Logging


The scope of this document is to describe how to enable logging on products built on the CampusNexus framework.

Configuring Logging

The default logging provider used by CampusNexus is NLog. NLog allows you to configure log targets, levels, rules, layouts, etc. through configuration.

To configure logging for CampusNexus products, you need to modify the nlog.config file contained within the application’s executing directory. For web applications, this file exists alongside the web.config file.

Above is an example of a config file that is configured with two targets: file and console. The logging rules define which target is executed based on level (Trace, Debug, Information, Warning, Error, and Fatal). The configuration above will log to a subfolder off the base directory whenever an Error or Fatal level is logged by the application. To log verbose diagnostic information, you can change the minLevel to Trace, which will log all levels of diagnostic information.

This link describes additional information regarding the configuration file. You can also find supported NLog targets here.

Writing Logs

There are three public types associated with the logging framework: ILoggerFactory, ILogger, and LoggerExtensions (extensions methods for ILogger):

There are two ways to enable logging in your class. The preferred way is to receive an ILogger interface as a constructor dependency. The IoC container will ensure that this dependency is wired for you:

If your class is a legacy class that does not support DI, you can use the ServiceLocator to retrieve an ILoggerFactory to create the logger:


Leave a Reply

Skip to toolbar