locked
logs are not generating in release mode using NLog RRS feed

  • Question

  • User-349240026 posted

    Hi Friends,

    I have window application where I am using Nlog dll and configuration.

    it is working fine and all logs are generating in file while in debug mode.

    once i set my application in release mode it is not generating logs.

    Wednesday, April 4, 2018 5:14 AM

Answers

  • User1400794712 posted

    Hi shallubhalla,

    NLog will look for a configuration file from the exe that includes your DLL. 

    So you will need to copy a configuration file for NLog everytime you want to use your DLL.

    Please make sure the nlog config file is included as part of your release build.

    You can take a look at this solution and check you configuration file.

    Or take some troubleshooting methods:

    1.Make sure that NLog finds the config file.It is recommended to use NLog.config located in the same directory as the application, but there are also other options.

    2.Configuration file is read when we create the first Logger. We can validate that if the configuration file is syntactically valid by creating one in the Main() method of the program.

    3.To eliminate the possibility that the logging rules are incorrect, add the rule which matches all loggers and all levels at the beginning of the <rules> section.

    4.If it still does not work, there is a possibility is that the code in the application may be incorrect. To make sure this is not the case, add the following code to the Main() method.

    5.If there is any problem with the target your're using (such as insufficient permissions when writing to a file), you should get an exception explaining the problem right from the place where the problem occurred.

    For more details, please refer to the source:

    https://github.com/NLog/NLog/wiki/Logging-troubleshooting

    Best Regards,

    Daisy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 5, 2018 7:28 AM

All replies

  • User1400794712 posted

    Hi shallubhalla,

    NLog will look for a configuration file from the exe that includes your DLL. 

    So you will need to copy a configuration file for NLog everytime you want to use your DLL.

    Please make sure the nlog config file is included as part of your release build.

    You can take a look at this solution and check you configuration file.

    Or take some troubleshooting methods:

    1.Make sure that NLog finds the config file.It is recommended to use NLog.config located in the same directory as the application, but there are also other options.

    2.Configuration file is read when we create the first Logger. We can validate that if the configuration file is syntactically valid by creating one in the Main() method of the program.

    3.To eliminate the possibility that the logging rules are incorrect, add the rule which matches all loggers and all levels at the beginning of the <rules> section.

    4.If it still does not work, there is a possibility is that the code in the application may be incorrect. To make sure this is not the case, add the following code to the Main() method.

    5.If there is any problem with the target your're using (such as insufficient permissions when writing to a file), you should get an exception explaining the problem right from the place where the problem occurred.

    For more details, please refer to the source:

    https://github.com/NLog/NLog/wiki/Logging-troubleshooting

    Best Regards,

    Daisy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 5, 2018 7:28 AM
  • User-349240026 posted

    Thanks Daisy,

    You are right. i was missing Nolog.config file in release folder.

    Steps I used for NLog

    1. Added Nlog.dll and  Nlog.Config in dll folder
    2. Added refference to these folder
    3. In dll property set 'copy to directory' as 'Copy always'
    4. I had to add nlog.config file in Release folder as well.

    My Cofiguration is like as below :

    <?xml version="1.0" encoding="utf-8" ?>

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

    <targets>
    <target xsi:type="File" name="log" fileName="${basedir}\logs\${date:format=dd-MM-yyyy}.log"
    layout="${longdate} ${uppercase:${level}} ${message}"
    archiveFileName="${basedir}/Log/log.{#####}.log"
    />

    </targets>

    <targets>
    <target name="mail" xsi:type="Mail"
    smtpServer="servername"
    from="EmailID"
    to="EmailID"
    subject="Exception occured." />
    </targets>

    <rules>


    <logger name="*" minlevel="trace" writeTo="log" />
    <logger name="*" minlevel="Fatal" writeTo="mail" />
    </rules>
    </nlog>

    Friday, April 6, 2018 10:16 AM