Good day!

the article says here - install the NLog package, then add an entry to the project's web config, and then insert this code somewhere:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <targets> <target name="logfile" xsi:type="File" fileName="C://file.txt" /> </targets> <rules> <logger name="*" minlevel="Info" writeTo="logfile" /> </rules> </nlog> 

Google says that there should be 1 more config file: NLog.config, where it should be placed. I added an empty config file and did so, but the logs did not work.

Tell me, did I do it right? Or it was necessary somehow in a different way?

thank

    1 answer 1

    After installation, we use the documentation on NLog ( https://github.com/nlog/nlog/wiki/Tutorial ) and add to Web.config

    The answer to the question is web.config .

    It turns out something like this:

     <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" /> <!-- ... описаниС Π΄Ρ€ΡƒΠ³ΠΈΡ… сСкций ... --> </configSections> <!-- ... Π΄Ρ€ΡƒΠ³ΠΈΠ΅ сСкции ... --> <nlog autoReload="true" xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <targets> <target name="logfile" xsi:type="File" fileName="C://file.txt" /> </targets> <rules> <logger name="*" minlevel="Info" writeTo="logfile" /> </rules> </nlog> </configuration> 

    Or you can configure different log output options:

     <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" /> <!-- ... описаниС Π΄Ρ€ΡƒΠ³ΠΈΡ… сСкций ... --> </configSections> <!-- ... Π΄Ρ€ΡƒΠ³ΠΈΠ΅ сСкции ... --> <nlog autoReload="true" xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <variable name="logDirectory" value="${basedir}/Content/logs/${shortdate}" /> <targets> <target name="TcpOutlet" xsi:type="NLogViewer" address="tcp4://localhost:4505"/> <target name="fileLogTrace" xsi:type="File" fileName="${logDirectory}/trace.txt" /> <target name="fileLogDebug" xsi:type="File" fileName="${logDirectory}/debug.txt" /> <target name="fileLogInfo" xsi:type="File" fileName="${logDirectory}/info.txt" /> <target name="fileLogErrors" xsi:type="File" fileName="${logDirectory}/errors.txt" /> </targets> <rules> <logger name="*" level="Info" writeTo="TcpOutlet" /> <logger name="*" level="Trace" writeTo="fileLogTrace" /> <logger name="*" level="Debug" writeTo="fileLogDebug" /> <logger name="*" level="Info" writeTo="fileLogInfo" /> <logger name="*" minlevel="Warn" writeTo="fileLogErrors" /> </rules> </nlog> </configuration>