我无法使用Log4Net将Spring.Net记录下来。我特别感兴趣的是看到围绕Aspects的日志记录。我正在使用一个非常简单的日志配置,类似于MovieFinder示例应用程序:
...
<logger name="Spring">
<level value="DEBUG" /> <!-- Have tried INFO as well, no different -->
<appender-ref ref="SpringAppender"/>
</logger>
<appender name="SpringAppender" type="log4net.Appender.RollingFileAppender">
<file value="..\Log\Spring_Log.txt"/>
<appendToFile value="true"/>
<maximumFileSize value="100MB"/>
<maxSizeRollBackups value="2"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level [%thread] %logger - %message%newline"/>
</layout>
</appender>
...
创建了文件“Spring_Log.txt”,但没有记录任何内容(即空文件)。 Log4Net目前正在为NHibernate和我们的自定义应用程序日志记录正确登录。我正在使用Spring.Net v1.2.0.20313和Log4Net v1.2.10.0。
还有其他人有这个问题,他们能够解决?非常感谢任何帮助,欢呼。
答案 0 :(得分:3)
正如Erich所说,你需要配置Common.Logging。 你的log4net配置文件很好。以下是我使用您的配置文件的内容:
2009-05-02 19:08:40,890 DEBUG [10] Spring.Objects.Factory.Support.AbstractObjectDefinitionReader - Loading XML object definitions from config [C:\Documents and Settings\pczapla\My Documents\Visual Studio 2008\Projects\TimeLogger\TimeLogger\bin\Debug\TimeLogger.exe.config#spring/objects]
2009-05-02 19:08:40,905 DEBUG [10] Spring.Objects.Factory.Support.AbstractObjectDefinitionReader - Using the following XmlReader implementation : System.Xml.XsdValidatingReader
2009-05-02 19:08:40,921 DEBUG [10] Spring.Objects.Factory.Xml.DefaultObjectDefinitionDocumentReader - Loading object definitions.
2009-05-02 19:08:40,921 DEBUG [10] Spring.Objects.Factory.Xml.ObjectDefinitionParserHelper - Loading object definitions...
以下是如何配置Common.Logging的快速指南:
添加Common.Logging&amp;它们与lib文件夹(C:\Program Files\Spring.NET 1.2.0\lib\Net\2.0\
)中的spring一起提供的Common.Logging.Log4Net程序集。
然后将以下配置添加到app.config
:
<configuration>
</configSections>
...
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
...
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4net">
<!-- Common Logging assumes that log4net is initialized -->
<arg key="configType" value="EXTERNAL"/>
<!-- Or it can configure log4net for you
<arg key="configType" value="FILE-WATCH" />
<arg key="configFile" value="path\to\your\log4net.config" />
-->
</factoryAdapter>
</logging>
</common>
</configuration>
就是这样。现在你应该从spring获得调试消息。
答案 1 :(得分:1)
Spring.NET使用Common.Logging。您是否将Common.Logging配置为登录到log4net?有关文档
,请参阅http://netcommon.sourceforge.net/documentation.htmlHTH, 埃里希