Visual Studio扩展项目中的Log4Net问题 [英] Log4Net problem in Visual Studio Extension project
问题描述
大家好,
我正在维护VSIX加载项项目以处理我的源项目。我需要在使用自定义加载项时记录特定位置的异常/错误。所以,我已经在我的加入项目中尝试了log4Net实用程序,用于此日志记录功能。我通过调试我的加载项目检查了
工作正常。但是,在我安装了自定义加载项的VSIX并尝试记录异常/错误之后,日志文件不会在特定位置生成。
我已附加了示例VSIX项目,我已经尝试使用Log4Net逻辑来记录异常/错误。
请向我建议解决此问题的任何解决方案。
< a href ="https://www.zeta-uploader.com/1414781448"target ="_ blank"title ="示例VSIX项目">示例VSIX项目
谢谢,
Ganesan R。
嗨GaneshRengasamy,
我已下载该项目并在我身边重现您的问题。
请修改您的配置文件,如下所示:
<?xml version =" 1.0"编码= QUOT; UTF-8英寸?>
< configuration>
< configSections>
< section name =" log4net" type =" log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
< / configSections>
< log4net>
< appender name =" RollingLogFileAppender"类型= QUOT; log4net.Appender.RollingFileAppender">
<! - log path - >
< param name =" File" value =" D:\ASPNETMVCExtension \" />
<! - 将日志附加到文件 - >
< param name =" AppendToFile" value =" true" />
<! - log keep days - >
< param name =" MaxSizeRollBackups" value =" 10" />
< param name =" StaticLogFileName" value =" false" />
<! - log farmat:2008-08-31.log - >
< param name =" DatePattern" value =" yyyy-MM-dd& quot; .log& quot;" />
< param name =" RollingStyle" value =" Date" />
< layout type =" log4net.Layout.PatternLayout">
< param name =" ConversionPattern" value ="%d [%t]%-5p%c - %m%n" />
< / layout>
< / appender>
< appender name =" ColoredConsoleAppender"类型= QUOT; log4net.Appender.ColoredConsoleAppender">
< mapping>
< level value =" ERROR" />
< foreColor value =" Red,HighIntensity" />
< / mapping>
< mapping>
< level value ="信息" />
< foreColor value =" Green" />
< / mapping>
< layout type =" log4net.Layout.PatternLayout">
< conversionPattern value ="%n%date {HH:mm:ss,fff} [%-5level]%m" />
< / layout>
< filter type =" log4net.Filter.LevelRangeFilter">
< param name =" LevelMin"值= QUOT;详情" />
< param name =" LevelMax"值= QUOT;致命" />
< / filter>
< / appender>
< root>
<! - (高)OFF>致命>错误>警告>信息>调查>全部(低) - >
< level value =" all" />
< appender-ref ref =" ColoredConsoleAppender" />
< appender-ref ref =" RollingLogFileAppender" />
< / root>
< / log4net>
< / configuration>修改相关代码如下:
public static class Logger
{
public static ILog Log {get;组; }
public static void Logg(字符串路径,异常异常)
{
//MessageBox.Show("Enter");
GlobalContext.Properties [" LogFileName"] = Path.Combine(path," ASPNETMVCExtension"); // path +" \\ASPNETMVCExtension" ;;
FileInfo f = new FileInfo(@"C:\ VSIXProject1 \ConsoleApp1 \ log4net.config"); //请修改此行
XmlConfigurator.Configure(f);
Log = LogManager.GetLogger(typeof(Command1));
if(Log!= null)
{
Log.Error(exception);
//MessageBox.Show("Exit");
}
}
}祝你好运,
Cole Wu
Hi All,
I am maintaining the VSIX add-in project to handle my source project. I need to log the exceptions/errors in particular location while using my custom add-in. So, I have tried log4Net utility in my addd-in project for this logging feature. It's working fine while I have checked with debugging my add-in project. But, after I have installed the VSIX of my custom add-in and trying to logging the exception/error, the logging file is not generated in the particular location.
I have attached the sample VSIX project which I have tried the Log4Net logic to logging the exception/error.
Please suggest any solution to me for resolve this problem.
Thanks,
Ganesan R.
Hi GaneshRengasamy,
I have downloaded the project and reproduce your issue on my side.
Please modify your configuration file like this:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/> </configSections> <log4net> <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <!--log Path--> <param name= "File" value= "D:\ASPNETMVCExtension\"/> <!--append log to file--> <param name= "AppendToFile" value= "true"/> <!--log keep days--> <param name= "MaxSizeRollBackups" value= "10"/> <param name= "StaticLogFileName" value= "false"/> <!--log farmat:2008-08-31.log--> <param name= "DatePattern" value= "yyyy-MM-dd".log""/> <param name= "RollingStyle" value= "Date"/> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" /> </layout> </appender> <appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender"> <mapping> <level value="ERROR" /> <foreColor value="Red, HighIntensity" /> </mapping> <mapping> <level value="Info" /> <foreColor value="Green" /> </mapping> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%n%date{HH:mm:ss,fff} [%-5level] %m" /> </layout> <filter type="log4net.Filter.LevelRangeFilter"> <param name="LevelMin" value="Info" /> <param name="LevelMax" value="Fatal" /> </filter> </appender> <root> <!--(high) OFF > FATAL > ERROR > WARN > INFO > DEBUG > ALL (low) --> <level value="all" /> <appender-ref ref="ColoredConsoleAppender"/> <appender-ref ref="RollingLogFileAppender"/> </root> </log4net> </configuration>Modify related code like this:
public static class Logger { public static ILog Log { get; set; } public static void Logg(string path, Exception exception) { //MessageBox.Show("Enter"); GlobalContext.Properties["LogFileName"] = Path.Combine(path, "ASPNETMVCExtension"); // path + "\\ASPNETMVCExtension"; FileInfo f = new FileInfo(@"C:\VSIXProject1\ConsoleApp1\log4net.config"); //please modify this line XmlConfigurator.Configure(f); Log = LogManager.GetLogger(typeof(Command1)); if (Log != null) { Log.Error(exception); //MessageBox.Show("Exit"); } } }Best regards,
Cole Wu
这篇关于Visual Studio扩展项目中的Log4Net问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!