Implementing a single log4net configuration file for multiple projects

I am trying to use a solution that I have compiled from several other answers. I am basically trying to use a single log4net configuration file for a solution that has multiple projects.

Here is my configuration 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 this is where I call 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 should configure the logger:

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

I have a log4net.config file in the solution folder and then added to the calling assembly as a linked file. When the application starts, it never gets into the configuration. I saw a couple of similar problems, but he never tuned in that way, hoping that someone could help.

+4
source share
1 answer

When using the associated configuration file for log4net as part of a Windows service project, to create a configuration file, you must set the Content value in the file properties. From there, in the deployment project, the file should be included in the project output file

+2
source

Source: https://habr.com/ru/post/1496571/


All Articles