我有一个控制台应用程序,并有一个包装Log4Net方法的类库。现在,当以调试模式运行应用程序时,它会写入日志,但是当它以发布模式构建时,它不写入日志文件。这将是什么解决方案?下面Log4Net不写登录发布模式 - 控制台应用程序
我的开发环境的示例代码和配置文件中给出的
- 的Visual Studio 2013的.NET Framework 4.5
控制台应用程序
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
log4net.GlobalContext.Properties["LogFileName"] = "TestLogin.txt";
Logger log = new Logger(typeof(Program));
log.Info("Logging is enabled!!");
}
}
}
应用.config在控制台应用程序
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<log4net>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value ="%property{LogFileName}"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level - %message%newline%exception" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="RollingFileAppender" />
</root>
</log4net>
</configuration>
类库
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
namespace Logging
{
public class Logger
{
private readonly ILog log = null;
public Logger(Type type)
{
log = LogManager.GetLogger(type);
}
public void Info(object message)
{
log.Info(message);
}
}
}
我按照后,并没有帮助我弄清楚为什么log4net的不日志文件写在释放模式?
log4net doesn't log when running a .Net 4.0 Windows application built in Release mode
我将使log4net的内部调试,试图了解发生了什么,如下所述:http://logging.apache.org/log4net/release/faq.html – Joe