log4net调试
public delegate void LogReceivedEventHandler(object source, LogReceivedEventArgs e);
public sealed class LogLog { /// <summary> /// The event raised when an internal message has been received. /// </summary> public static event LogReceivedEventHandler LogReceived;
基于以上,log4net添加了一个适配类,可以使用:
/// <summary> /// Subscribes to the LogLog.LogReceived event and stores messages /// to the supplied IList instance. /// </summary> public class LogReceivedAdapter : IDisposable { private readonly IList items; private readonly LogReceivedEventHandler handler; /// <summary> /// /// </summary> /// <param name="items"></param> public LogReceivedAdapter(IList items) { this.items = items; handler = new LogReceivedEventHandler(LogLog_LogReceived); LogReceived += handler; } void LogLog_LogReceived(object source, LogReceivedEventArgs e) { items.Add(e.LogLog); } /// <summary> /// /// </summary> public IList Items { get { return items; } } /// <summary> /// /// </summary> public void Dispose() { LogReceived -= handler; } }
使用
using(LogReceivedAdapter log=new LogReceivedAdapter (集合)) { ilog=LogMange.getLog(); }