为什么log4net没有写入文件?

我已经添加了log4net的所有部分,但它没有写入该文件。
我正在使用VS2012 LoadTest项目。

运行LoadTest项目时, System.Console.WriteLineDebug.WriteLine()不起作用。

我添加了汇编信息行:

 [assembly: log4net.Config.XmlConfigurator(ConfigFile = "web.config", Watch = true)] //For log4net 1.2.10.0 

我有:
– 添加了webconfig部分
– 初始化已配置的XML初始化程序
– 使用正确的日志初始化新的log4net

我的app.config:

   

我的课:

 //------------------------------------------------------------------------------ //  // This code was generated by a tool. // Runtime Version:4.0.30319.17929 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. //  //------------------------------------------------------------------------------ namespace WebAndLoadTestProject1 { using System; using System.Collections.Generic; using System.Diagnostics; using System.Text; using log4net; using log4net.Core; using Microsoft.VisualStudio.TestTools.WebTesting; public class Settings_CacheExplosion : WebTest { private static readonly ILog activityLog = LogManager.GetLogger("Activity"); private static int _ctidsCounter { get; set; } public static int CtidsCounter { get { if (_ctidsCounter == 2000) { _ctidsCounter = 1000; } return _ctidsCounter++; } set { _ctidsCounter = value; } } public Settings_CacheExplosion() { this.PreAuthenticate = true; CtidsCounter = 1000; log4net.Config.XmlConfigurator.Configure(); } public override IEnumerator GetRequestEnumerator() { WebTestRequest request1 = new WebTestRequest("http://clientservice.mam.qasite-services.com/settings"); request1.Method = "POST"; Debug.WriteLine(string.Format("ctid={0}", CtidsCounter)); request1.QueryStringParameters.Add("ctid", CtidsCounter.ToString(), false, false); StringHttpBody request1Body = new StringHttpBody(); request1Body.ContentType = ""; request1Body.InsertByteOrderMark = false; request1Body.BodyString = ""; request1.Body = request1Body; activityLog.Debug(string.Format("ctid={0}", CtidsCounter)); //Console.WriteLine(string.Format("ctid={0}", CtidsCounter)); yield return request1; request1 = null; } } } 

谢谢

看看你的app.config

这可以确保应用程序在启动时出现错误时拒绝在.NET 4.0上启动。

如果您使用的是Framework .NET4.5,则log4net不支持它。 请参阅http://logging.apache.org/log4net/release/features.html中的框架部分

如果您希望从app.config读取log4net,则必须将其添加到AssemblyInfo.cs文件中:

 [assembly: log4net.Config.XmlConfigurator(Watch = true)] 

使用而不是 。 在您的xml配置部分。