How to configure log4net to write logs in Visual Studio 2015 Extensions

拥有回忆 提交于 2019-12-11 16:22:51

问题


I'm trying to port my extension of Visual Studio from 2012 - 2013 to 2015. I have a log4net configuration file with the following section:

<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
  <file value=".\mylog.log" /> 
  <appendToFile value="true" />
  <maximumFileSize value="1000KB" />
  <maxSizeRollBackups value="2" />

  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="[%d{ddMMM HH:mm:ss,fff}] %5level %logger (%line) - %message%newline" />
  </layout>
</appender>

In the previous versions of VS, I was able to find my logs under

C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\log
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\log

but now there's nothing under

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\log

What's the best practice here (without carving a fixed path in the config file!!)?

Thank you!


回答1:


You can use "DebugAppender" on your log4net configuration XML file.

<appender name="DebugAppender" type="log4net.Appender.DebugAppender">
    <immediateFlush value="true" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="*%-10level %-30date %message [%logger] [%thread] %newline" />
    </layout>
</appender>

This will output your log into the Ouput Console in VS.

like this

Cheers,



来源:https://stackoverflow.com/questions/38282709/how-to-configure-log4net-to-write-logs-in-visual-studio-2015-extensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!