I have a file log4net.xml
in the root of my solution. The file property for copying to bin is set to Always copy
. I have confirmed that the file copies to the bin directory.
Within the config I have set up a file appender (basically a copy paste from the documentation):
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="Logs\\log.log" />
<appendToFile value="true" />
<rollingStyle value="Date"/>
<datePattern value="yyyyMMdd-HHmmss" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
I also have this line in AssemblyInfo.cs
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.xml", Watch = true)]
And loggers are set up like this in code files:
private static ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
I added log4net.Config.XmlConfigurator.Configure();
(and also with FileInfo
parameter) to the main Program.cs
too.
However if I execute the program the expected log file is not created. I suspect log4net isn't even reading the config file.
Am I missing something? Executing from within VS also doesn't work (though somehow it is picking up the Console Appender part).
Similar posts:
- StackOverflow question 1 -- not applicable
- StackOverflow question 2 -- not applicable
- StackOverflow question 3 -- conforms already
Thanks in advance.
EDIT
So I got this working in VS by deleting a copy/pasted part from the documentation:
<root>
<level value="DEBUG" />
<appender-ref ref="A1" />
</root>
However, running from the exe still doesn't work