2011-09-19 30 views

回答

2

這可以很容易地完成。 Spring使用Common.Logging。您可以從Spring.Objects.Factory.*類中獲取日誌輸出並查找... Creating instance of Object 'your-id-here' ...消息。

請注意,您必須登錄DEBUG級別,這意味着您會看到很多其他信息。

下的app.config將日誌創建調用控制檯,使用log4net的:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 

<configSections> 
    <sectionGroup name="common"> 
     <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" /> 
    </sectionGroup> 

    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/> 
    </configSections> 

    <common> 
    <logging> 
     <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net"> 
     <arg key="configType" value="INLINE" /> 
     </factoryAdapter> 
    </logging> 
    </common> 

    <log4net> 
    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender"> 
     <layout type="log4net.Layout.PatternLayout"> 
     <conversionPattern value="%date [%thread] %-5level %logger %ndc - %message%newline" /> 
     </layout> 
    </appender> 

<!-- this logger will catch creation messages --> 

    <logger name="Spring.Objects.Factory"> 
     <level value="DEBUG" /> 
     <appender-ref ref="ConsoleAppender" /> 
    </logger> 
    </log4net> 

</configuration> 

所以大部分是樣板Common.Logging和log4net的配置,這是對Common.Logging website有據可查。如果你想附加到一個文件或其他東西,請參閱log4net文檔。

相關問題