All Projects → unitycontainer → Nlog

unitycontainer / Nlog

Licence: apache-2.0
Adapter for NLog

Build status License NuGet NuGet

NLog adapter for Unity container

Unity extension to integrate with popular NLog logger.

Getting Started

  • Reference the Unity.NLog package from NuGet.
Install-Package Unity.NLog

Registration:

  • Add NLogExtension extension to the container
container = new UnityContainer();
container.AddNewExtension<NLogExtension>();
  • Where required add ILogger interface to resolved constructor.
public class LoggedType
{
    public LoggedType(ILogger log)
    {
    }
  ...
}
  • If you want to custom the extension (In this case, get only the class name instead of the full name), you have to instantiate NLogExtension to set properties and add this extension to Unity
var ext = new NLogExtension{
    GetName = (t, n) => t.Name
};
container.AddExtension(ext);
  • Log normally...

Code of Conduct

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information, see the .NET Foundation Code of Conduct

Contributing

See the Contributing guide for more information.

.NET Foundation

Unity Container is a .NET Foundation project

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].