0

Below is the nlog configuration in web.config file

 <configuration>
       <configSections>
         <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
      </configSections>
    <nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <targets>
         <target name="logfile" xsi:type="File" fileName="${basedir}/MyLogs/${date:format=yyyy-MM-dd}-api.log" />
        <target name="logconsole" xsi:type="Console" />
    
        </targets>
        <rules>
           <logger name="*" minlevel="Trace" writeTo="logfile" />
           <logger name="*" minlevel="Info" writeTo="logconsole" />
      
       </rules>
    </nlog>
    </configuration>

This works perfectly when I run from visual studio. But when I dockerize this and put in Windows container and run the application the contents are written to file target inside the container, but then is getting written in console target. I say this because when I do a docker logs I do not see ant logs getting written to output. Can any one suggest a solution

Venkatesh
  • 320
  • 2
  • 18

1 Answers1

1

As you mentioned web.config, I'm assuming you are trying to run a webapp on IIS in a container?

If that is the case, what you are running into is the fact that your app is not what the container runs when it boots, it actually launches Service Monitor, the output from which is what is sent to stdout and thus displayed in the docker logs.

As your webapp is not the linked process, it cannot write to the stdout pipe that docker logs command renders, so you won't be able to use the console logging from nlog while hosting with IIS.

CodedBeard
  • 862
  • 8
  • 19