Pergunta

I'm trying to use a solution that I've put together from a few other answers on here. Basically I'm trying to use one log4net config file for a solution that has multiple projects.

Here is my config file:

<?xml version="1.0" ?>
  <log4net>
    <appender name="FileMonitorAppender" type="log4net.Appender.FileAppender">
      <file type="log4net.Util.PatternString" value="C:\Documents and Settings\user1\My Documents\My Box Files\FOBS\logs\Box File Monitor %date{MM.dd.yyyy'_'hh.mm.ss''}.txt" />
      <appendToFile value="true"/>
      <layout type="log4net.Layout.PatternLayout">
        <header value="[START: Box File Monitor Run %date]%newline" type="log4net.Util.PatternString" />
        <conversionPattern value="%date{HH:mm:ss} - %-5level- %message%newline" />
        <footer value="[END: Box File Monitor Run]" />
      </layout>
    </appender>

    <root>
      <level value="ALL"/>
      <appender-ref ref="FileMonitorAppender" />
    </root>
  </log4net>

and here is where I'm calling the logger in code:

private static readonly ILog _log = LogManager.GetLogger("Duke.Mobile.FileMonitorAutomation.FileMonitor");

and I also have this in the calling assembly which is supposed to configure the logger:

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log4Net.config", Watch = true)]

I have the log4net.config file in a solution folder and then have it added to the calling assembly as a linked file. When the app runs, it never hits the configuration. I've seen a couple of similar problems but it's never set up exactly this way, hoping someone can help.

Foi útil?

Solução

When using a linked config file for log4net, within a Windows service project, the config file's build action needs to be set to 'Content' in the file's properties. From there, in the deployment project, the file needs to be included in the project output

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top