سؤال

In my C#, I'm working a library (Outlook Add-in).

I'm using NLog for .NET 3.5

The problem is that on my development machine, sometimes NLog doesn't write the logs to the file.

I'm using NLog version 2.0.0.0 and the problem occours with Windows 8.1 Pro

Here is the App.config

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

  <configSections>
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
  </configSections>

  <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <targets>
      <target name="file" xsi:type="File"
              fileName="${specialfolder:folder=ApplicationData}\\AppName\\Logs\\log.txt"
              archiveEvery="Day"
              archiveNumbering="Rolling"
              maxArchiveFiles="30"
              layout="${date:format=yyyy-MM-dd HH\:mm\:ss} ${level:uppercase=true} ${logger} - ${message} ${exception:format=tostring}"/>
    </targets>
    <rules>
      <logger name="*" minlevel="Debug" writeTo="file"/>
    </rules>
  </nlog>

  <startup>
    <supportedRuntime version="v2.0.50727"/>
  </startup>

</configuration>

In the distribution, currently I do not include the file NLog.config, but also including it, I haven't seen any change

The one below is the method in which the problem occours, should I have to include special libraries in my distribution? (Like stdole.dll as example?)

    private void AddinModule_AddinStartupComplete(object sender, EventArgs e)
    {
        String aversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
        log.Debug("AddinStartupComplete called version: {0}", aversion);
    }
هل كانت مفيدة؟

المحلول

Ok, it seems I have found a solution.
First of all, I modified the App.config file as follows:

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

  <startup>
    <supportedRuntime version="v2.0.50727"/>
  </startup>

</configuration>

Then I included a file NLog.config as follows:

<?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">

  <targets> 
    <target name="file" xsi:type="File" 
            fileName="${specialfolder:folder=ApplicationData}\\AppName\\Logs\\log.txt"
            archiveEvery="Day"
            archiveNumbering="Rolling"
            maxArchiveFiles="30"            
            layout="${date:format=yyyy-MM-dd HH\:mm\:ss} ${level:uppercase=true} ${logger} - ${message} ${exception:format=tostring}"/>
  </targets> 

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

</nlog>

I also specified to include in the setup the file adxloader64.dll, though the compiler would give me a warning saying that the resource was not compatible with the type of setup specified: x86.

Note: I'm building a setup using Add-in Express 7.4.x

Now there is just one point to clarify: I should check if this setup works also on a 32-bit Windows system (I have to test it on a Windows 7 home)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top