4

When I log in my dev environment there is no problem but when I deploy with a windows installer no log files are produced:

<log4net>
    <root>
      <level value="ALL"/>
      <appender-ref ref="LogFileAppender"/>
    </root>
    <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
      <param name="File" value="C:\Logs\log-file.txt"/>
      <param name="AppendToFile" value="true"/>
      <rollingStyle value="Size"/>
      <maxSizeRollBackups value="10"/>
      <maximumFileSize value="10MB"/>
      <staticLogFileName value="true"/>
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%date [%thread] %-5level %logger [%C{1}.%M] - %message%newline"/>
      </layout>
    </appender>
  </log4net>

I read that it may be that it cannot find the app.config but how do I tell it where to find it?

Philipp M
  • 1,877
  • 7
  • 27
  • 38
Pat Mustard
  • 1,852
  • 9
  • 31
  • 58
  • 1
    Normally, when building, the app.config file is "renamed" to a file matching your executable and placed alongside. So, if you executable is named "Foo.exe", the app.config file will be named "Foo.exe.config". You don't need to do anything about that, it just happens. Check if that file is present in your install folder. – Jensen Nov 14 '13 at 09:17

2 Answers2

3

The issue was that log4net couldn't find the config file at run time after the dll was installed. Fixed by a suggestion here. In the end, my solution looked like this:

FileInfo fi = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "Assembly.dll.config");
log4net.Config.XmlConfigurator.Configure(fi);
_log.Info("Hello logging...");

Thank you for all of your input!

Community
  • 1
  • 1
Pat Mustard
  • 1,852
  • 9
  • 31
  • 58
0

The app.config project file is turned to the the application.exe.config file after compilation. Maybe you are not deploying it with the installer?

Ignacio Soler Garcia
  • 21,122
  • 31
  • 128
  • 207