Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use NLog for a DLL

Tags:

c#

logging

dll

nlog

I am trying to implement a simple log using Nlog Refresh 1.0 for a class Library project. It seems nlog does not create a logfile when it's instantiated from within a dll.

Is there some other way around this ?

my config file looks like this:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      throwExceptions="true">

    <targets>
      <target name="file" xsi:type="File" fileName="${basedir}/nlog.txt" />
        <target name="console" xsi:type="Console" />
    </targets>

    <rules>
        <logger name="*" minlevel="Info" writeTo="file" />
        <logger name="*" minlevel="Info" writeTo="console" />
    </rules>

</nlog>

I know there is nothing wrong with this config because it works from within an exe project.

Edit: just to clarify: I have no access to the calling program which uses my dll as a plugin. The calling program is in fact outlook which uses my dll as a plugin. I would want to keep a log which is only relevant to my dll and has nothing to do with outlook itself.

like image 685
Oysio Avatar asked Mar 11 '11 13:03

Oysio


People also ask

What is NLog DLL?

NLog is a flexible and free logging platform for various . NET platforms, including . NET standard. NLog makes it easy to write to several targets. (database, file, console) and change the logging configuration on-the-fly.

How do I use NLog in Visual Studio?

Create a Console Application project in Visual Studio. Install NLog and its dependencies. Create and configure the NLog logger. Integrate the logger into the C# Console Application.


1 Answers

you have to add the nlog.config to the location of the exe file that uses the dll!

Edit: You don't have to modify the exe file just place the nlog.config in the same directory, if that is no option i guess you will have to configure it from code https://github.com/nlog/NLog/wiki/Configuration-API

like image 130
Peter Avatar answered Oct 31 '22 00:10

Peter