Unity extension to integrate with popular NLog logger.
- Reference the
Unity.NLog
package from NuGet.
Install-Package Unity.NLog
- 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...