您的位置:首页 > 其它

在Excel Add-in中使用log4NET

2012-02-14 16:23 288 查看
在Excel Add-in中没有办法设定配置文件。所以我们需要在程序中设定Log4NET的配置。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Excel;
using log4net;
using System.Diagnostics;
using System.IO;

namespace ExcelAddIn4
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
try
{
log4net.Config.BasicConfigurator.Configure(new log4net.Appender.FileAppender(
new log4net.Layout.PatternLayout("%d [%t]%-5p %c [%x] - %m%n"), @"C:\******\testfile.log"));

s.Close();
ILog log = LogManager.GetLogger(typeof(ExcelAddIn4.Globals));
log.Error("dddddddd");
}
catch (Exception ex)
{
Debug.Print(ex.Message);
}
}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}

#region VSTO generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}

#endregion
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: