-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Visual Studio Support
NLog integrates with Visual Studio®
NLog supports Intellisense when editing XML configuration files. Install the NLog.Schema-nuget-package and update the NLog.config
-file:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd">
<!-- configuration goes here -->
</nlog>
Alternative enable "Automatically download DTDs and schemas" (Visual Studio Options), then Intellisense works with using direct URL:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd http://www.nlog-project.org/schemas/NLog.xsd">
<!-- configuration goes here -->
</nlog>
Notice Intellisense will only work in Visual Studio when using xsi:type="..."
:
<target xsi:type="TypeName"/>
And not:
<target type="TypeName"/>
NLog Setup registers the appropriate AssemblyFolders entry in registry so that Visual Studio is able to locate the *.dll files and present them in Add Reference dialog. This is supported in all Visual Studio versions.
NLog comes with 3 sample configuration files that can be quickly added to you project through Add New Item dialog. They are:
- configuration file that defines one File Target (typical)
- configuration file that defines one Console Target
- empty configuration file
Please note that you need to change “Copy To Output Directory” option of properties of NLog.config to “Copy Always”
Note that “New Item” templates are supported on Visual Studio 2005 and higher (including Express Editions).
NLog installs a Visual Studio 2005 Code Snippet called “nlogger” that can be used to quickly declare a logger instance. It inserts the following piece of text:
private static Logger logger = LogManager.GetCurrentClassLogger();
- Troubleshooting Guide - See available NLog Targets and Layouts: https://nlog-project.org/config
- Getting started
- How to use structured logging
- Troubleshooting
- FAQ
- Articles about NLog
-
All targets, layouts and layout renderers
Popular: - Using NLog with NLog.config
- Using NLog with appsettings.json