在Excel Add-in中使用log4NET
在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
}
}
征诛志异,三让两家王朝;功同开辟,一桮万古江南。

浙公网安备 33010602011771号