Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to configure logging in Spring.NET using log4net?
    primarykey
    data
    text
    <p>I would like use from Spring.NET Aspect library Logging aspect together with log4Net. I found <a href="http://netcommon.sourceforge.net/docs/1.2.0/reference/html/logging.html#logging-adapters-log4net" rel="noreferrer">this article</a> how to use log4Net with Common Logging API.</p> <p>My test application is console and based on .NET 4.0 Client profile.</p> <h3>1st Attempt</h3> <p>So I refer in my project these libraries:</p> <ul> <li>Spring.Core version 1.3.2.40943, runtime v4.0.30319</li> <li>Spring.AOP version 1.3.2.40943, runtime v4.0.30319</li> <li>Common.Logging version: 1.2.0.0, runtime v1.0.3705</li> </ul> <p>Assemblies above I have from Program Files\Spring.NET 1.3.2\bin\net\4.0</p> <ul> <li>log4net version: 1.2.10.0, runtime v2.0.50727</li> </ul> <p>I couldn’t find assembly Common.Logging.Log4Net.dll in <em>Program Files\Spring.NET 1.3.2\bin \net\4.0</em> so I download this assembly <a href="http://netcommon.sourceforge.net/downloads.html" rel="noreferrer">from SourceForge</a>:</p> <ul> <li>Common.Logging.Log4Net version 2.0.0.0 runtime v2.0.50727</li> </ul> <p>I configured logger in app.config:</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;configuration&gt; &lt;configSections&gt; &lt;sectionGroup name="spring"&gt; &lt;section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/&gt; &lt;section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/&gt; &lt;/sectionGroup&gt; &lt;sectionGroup name="common"&gt; &lt;section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" /&gt; &lt;/sectionGroup&gt; &lt;section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/&gt; &lt;/configSections&gt; &lt;common&gt; &lt;logging&gt; &lt;factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net"&gt; &lt;arg key="configType" value="INLINE" /&gt; &lt;/factoryAdapter&gt; &lt;/logging&gt; &lt;/common&gt; &lt;log4net&gt; &lt;appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender"&gt; &lt;layout type="log4net.Layout.PatternLayout"&gt; &lt;conversionPattern value="%date [%thread] %-5level %logger %ndc - %message%newline" /&gt; &lt;/layout&gt; &lt;/appender&gt; &lt;root&gt; &lt;level value="DEBUG" /&gt; &lt;appender-ref ref="ConsoleAppender" /&gt; &lt;/root&gt; &lt;logger name="myLogger"&gt; &lt;level value="DEBUG" /&gt; &lt;/logger&gt; &lt;/log4net&gt; &lt;spring&gt; &lt;context&gt; &lt;resource uri="config://spring/objects"/&gt; &lt;/context&gt; &lt;objects xmlns="http://www.springframework.net"&gt; &lt;/objects&gt; &lt;/spring&gt; &lt;/configuration&gt; </code></pre> <p>and tried this:</p> <pre><code>ILog log = LogManager.GetLogger("myLogger"); log.Error("hello world"); </code></pre> <p>I got this runtime error:</p> <blockquote> <p>{"Could not configure Common.Logging from configuration section 'common/logging'."}</p> </blockquote> <p>Inner exception:</p> <blockquote> <p>{"An error occurred creating the configuration section handler for common/logging: Unable to create type 'Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net' (E:\C# PROJECTS\STUDY\SPRING.NET\SpringNet.Aspects\LoggingWithLog4Net\bin\Debug\LoggingWithLog4Net.vshost.exe.Config line 18)"}</p> </blockquote> <p>StackTrace:</p> <blockquote> <p>at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object&amp; result, Object&amp; resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object&amp; result, Object&amp; resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object&amp; result, Object&amp; resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object&amp; result, Object&amp; resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey) at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName) at System.Configuration.ConfigurationManager.GetSection(String sectionName) at System.Configuration.ConfigurationSettings.GetConfig(String sectionName) at Common.Logging.ConfigurationReader.GetSection(String sectionName)<br> at Common.Logging.LogManager.BuildLoggerFactoryAdapter()</p> </blockquote> <h3>2nd Attempt</h3> <p>I think problem must be in version of assembly Common.Logging.Log4Net <em>version 2.0.0.0 runtime v2.0.50727</em>. Because I used Common.Logging <em>version: 1.2.0.0, runtime v1.0.3705</em>.</p> <p>So I changed Common.Logging version from 1.2.0.0 to 2.0.0.0. I used Common.Logging from <a href="http://netcommon.sourceforge.net/downloads.html" rel="noreferrer">SourceForge</a>.</p> <p>And tested again. I got this error:</p> <blockquote> <p>Unable to create type 'Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net'</p> </blockquote> <p>Inner exception:</p> <blockquote> <p>{"Could not load file or assembly 'Common.Logging.Log4Net' or one of its dependencies. The system cannot find the file specified.":"Common.Logging.Log4Net"}</p> </blockquote> <p>StackTrace:</p> <blockquote> <p>at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark&amp; stackMark, Boolean loadTypeFromPartialName) at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark&amp; stackMark) at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) at Common.Logging.ConfigurationSectionHandler.ReadConfiguration(XmlNode section) in c:\CCNet\netcommon\trunk\modules\Common.Logging\src\Common\Common.Logging\Logging\ConfigurationSectionHandler.cs:line 130</p> </blockquote> <h3>3rd and last attempt</h3> <p>Finally I found assembly Common.Logging.Log4Net version 1.2.0.2 in spring examples so I used it.</p> <ul> <li>Common.Logging.Log4Net version 1.2.0.2</li> <li>Common.Logging version 1.2.0.0</li> <li>log4Net 1.2.10.0</li> </ul> <p>Tested and got again error:</p> <blockquote> <p>{"Could not configure Common.Logging from configuration section 'common/logging'."}</p> </blockquote> <p>Inner exception:</p> <blockquote> <p>{"An error occurred creating the configuration section handler for common/logging: Unable to create type 'Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net' (E:\C# PROJECTS\STUDY\SPRING.NET\SpringNet.Aspects\LoggingWithLog4Net\bin\Debug\LoggingWithLog4Net.vshost.exe.Config line 18)"}</p> </blockquote> <p>StackTrace:</p> <blockquote> <p>{"Unable to create type 'Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net'"}</p> </blockquote> <p>I am really confuse what I do bad? Some problem with assemblies version?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload