NLog in WCF Service

Can I use NLog in a WCF service? I try, but cannot make it work.

First, I set up a simple configuration in a Windows Forms application to verify the settings were correct and wrote a log file (I write to a network location using a name and not an IP address).

Then I did the same in the WCF service. This did not work.

To check permissions, I added code to use TextWriter.

        TextWriter tw = new StreamWriter(fileName);
        tw.WriteLine(DateTime.Now);
        tw.Close();

This worked fine, so I know that I can write in this place.

+3
source share
3 answers

See my comment on the original question on how to enable NLog internal logging.

To enable NLog internal logging, change the top of the NLog configuration to look like this:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.mono2.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       
      autoReload="true"       
      internalLogLevel="Trace"       
      internalLogFile="nlog_log.log"       
> 

internalLogLevel internalLogFile.

internalLogToConsole true false, .

throwExceptions, NLog, . false, . true, , NLog.

, , NLog :

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.mono2.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       
      autoReload="true"       
      internalLogLevel="Trace"       
      internalLogFile="nlog_log.log"       
      internalLogToConsole="true"
      throwExceptions="true"
> 

, NLog . (NLog.config) "" ( app.config web.config)? () , ( ) ?

0

, NLog.config , .svc , Bin.

WCF, , , , , bin, NLog . , -, ( , ).

!

0

Put your NLog configuration in the web.config file . For instance:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
  </configSections>

  . . . (lots of web stuff)

  <nlog>
    <targets>
      <target name="file" xsi:type="File" fileName="${basedir}/logs/nlog.log"/>
    </targets>
    <rules>
      <logger name="*" minlevel="Trace" writeTo="file" />
    </rules>
  </nlog>
</configuration>
0
source

Source: https://habr.com/ru/post/1789634/


All Articles