Winforms Windows窗体应用程序中的log4Net未写入日志文件

Winforms Windows窗体应用程序中的log4Net未写入日志文件,winforms,c#-4.0,log4net,Winforms,C# 4.0,Log4net,我有一个Windows窗体应用程序,我正在尝试实现log4net,以便编写一些日志。然而,我似乎无法让它发挥作用 XmlConfigurator.Configure(); 我的执行情况如下:- XmlConfigurator.Configure(); log4Net.config:- XmlConfigurator.Configure(); 在我的.cs里 XmlConfigurator.Configure(); 使用log4net; [程序集:log4net.Config.XmlC

我有一个Windows窗体应用程序,我正在尝试实现log4net,以便编写一些日志。然而,我似乎无法让它发挥作用

XmlConfigurator.Configure();
我的执行情况如下:-

XmlConfigurator.Configure();
log4Net.config:-

XmlConfigurator.Configure();

在我的.cs里

XmlConfigurator.Configure();
使用log4net;
[程序集:log4net.Config.XmlConfigurator(Watch=true)]
[程序集:log4net.Config.Repository()]
公共部分类Form1:Form
{
public static readonly ILog log=LogManager.GetLogger(“NotifMailer”);
私有无效按钮1\u单击(对象发送者,事件参数e)
{
//CreateFolder();
log4net.Config.BasicConfigurator.Configure();
if(log.iserror已启用)
{
尝试
{
错误(“页面加载失败:”);
}
捕获(异常exc)
{
字符串异常=异常消息;
}
}
if(log.IsDebugEnabled)
{
尝试
{
调试(“成功加载应用程序”);
}
捕获(异常exc)
{
字符串异常=异常消息;
}
}
}
}
正如您从这段代码中看到的,我做了一个小测试,通过代码“//CreateFolder();”创建了一个文件和文件夹,这是可行的,因此权限没有问题

XmlConfigurator.Configure();
我做错了什么

XmlConfigurator.Configure();
谢谢你的帮助和时间

XmlConfigurator.Configure();
更新

XmlConfigurator.Configure();
Log4Net.config:-

XmlConfigurator.Configure();

App.Config:-

XmlConfigurator.Configure();

Assembly.cs:-

XmlConfigurator.Configure();
[程序集:log4net.Config.XmlConfigurator(ConfigFile=“log4net.Config”,Watch=true)]
表格1.cs:-

XmlConfigurator.Configure();
private static readonly ILog log=LogManager.GetLogger(typeof(Form1));
私有无效按钮1\u单击(对象发送者,事件参数e)
{
//log4net.Config.BasicConfigurator.Configure();
XmlConfigurator.Configure(新文件信息(ConfigurationManager.AppSettings[“log4net配置文件”);
错误(“页面加载失败:”);
调试(“成功加载应用程序”);
}

不过仍然不走运

我通常不会使用assembly属性连接log4net

XmlConfigurator.Configure();
如果使用app/web.confg外部的配置文件,则根元素应为:

XmlConfigurator.Configure();

XmlConfigurator.Configure();
log4net.Config.BasicConfigurator.Configure()

XmlConfigurator.Configure();
这是一个简单的配置,只支持写入控制台,并且忽略配置文件

XmlConfigurator.Configure();
您应该使用XmlConfigurator而不是BasicConfiguration来发现我的问题

XmlConfigurator.Configure();
我应该做的

XmlConfigurator.Configure();
在Program.cs内部,因为它必须在初始化记录器之前运行该段代码

XmlConfigurator.Configure();
private static readonly ILog log = LogManager.GetLogger(typeof(Form1));

我已经在程序集中尝试过了:([Assembly:log4net.Config.XmlConfigurator(ConfigFile=“log4net.Config”,Watch=true)]嗨,Bronumski,你的根与我的根有什么不同?对我来说,它们看起来很像similar@Johann在外部文件中,它应该是“log4net”而不是“configuration”@Johann您可以更新问题以包含log4net.config文件的完整内容吗?@Johann您还需要包含配置文件的名称或扩展名。请参阅我的更新答案。我已经删除了BasicConfigurator,XmlConfigurator仍然没有成功//log4net.config.BasicConfigurator.Configure();log4net.Config.XmlConfigurator.Configure()。