---
title: "NLog Connector"
description: "Lacuna PKI NLog Connector, the optional PKI SDK package that forwards the log messages generated by the SDK to NLog, with a configuration example."
canonical: "https://docs.lacunasoftware.com/en-us/articles/pki-sdk/optional-packages/nlog-connector"
locale: "en"
product: "PKI SDK"
last_updated: "2026-07-14"
---

# NLog Connector

The package [Lacuna PKI NLog Connector](https://www.nuget.org/packages/Lacuna.Pki.NLogConnector/) enables sending log
messages generated by the PKI SDK to the [NLog](http://nlog-project.org/) logging library.

## Usage

All you need to do is make the following call somewhere in your code, preferably on the startup of your application
or website:

```cs
Lacuna.Pki.NLogConnector.NLogLogger.Configure();
```

From then on, all log messages generated by the SDK will be forwarded to NLog. Configuration of NLog, however, is up
to you. The following would be an example of a `web.config`/`app.config` file to save log messages to a file:

```xml
<?xml version="1.0" encoding="utf-8"?>
<configuration>
	<configSections>
		<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
	</configSections>
	<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
		<targets async="true">
			<target name="pkiLog" xsi:type="File" fileName="C:\Logs\LacunaPKI.log" layout="${longdate} ${level}: ${message}" />
		</targets>
		<rules>
			<logger name="Lacuna.Pki.*" writeTo="pkiLog" />
		</rules>
	</nlog>
</configuration>
```

> **Note**
>
> It is very important to specify asynchronous logging (`async="true"` on the
> `targets` tag), otherwise the performance of the SDK might be considerably
> impaired.

The messages are sent with various logger names according to where the message
was originated, but all logger names are preceded by "Lacuna.Pki." (hence the
`name="Lacuna.Pki.*"` attribute on the `logger` tag).

## Dependency on NLog

In order to maximise compatibility, the package depends on an old version of the NLog package, but we strongly recommend
that you install the latest version.

## Source code

This package is open source, hosted on [BitBucket](https://bitbucket.org/Lacunas/pkinlogconnector). Feel free to fork
it if you need to make any customizations.
