Spring.net可以记录它作为构造函数对象做什么吗?

发布于 2024-12-05 06:48:35 字数 174 浏览 1 评论 0原文

无论如何,是否有spring.net来记录它在构造对象时在做什么? 我需要在我的应用程序中

Constructing Object A
Constructing Object B
etc etc.....

解决循环依赖性,并且看到春季创建对象的顺序可能是巨大的帮助。

Is there anyway to get Spring.Net to log what it's doing as it constructs objects? Something on the order of

Constructing Object A
Constructing Object B
etc etc.....

I need to resolve a circular dependency within my application, and seeing the order in which Spring is creating the objects could be a huge help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拿命拼未来 2024-12-12 06:48:35

这很容易做到。春季使用 concom.logging 。您可以从spring.objects.factory中获取记录输出。

请注意,您必须在debug级别上登录,这意味着您也会看到很多其他信息。

以下app.config将使用log4net将CREATION调用记录到控制台:

<?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>

因此,大多数是boiler-plate common.logging和log4net Configuration,该配置在 common.logging 。如果要附加到文件或其他内容,请参见Log4net文档。

This can easily be done. Spring uses Common.Logging. You can grab logging output from Spring.Objects.Factory.* classes and look for ... Creating instance of Object 'your-id-here' ... messages.

Note that you have to log at DEBUG level, which means you'll see quite a lot of other information too.

The following app.config would log creation calls to the console, using 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>

So most of this is boiler-plate Common.Logging and log4net configuration, which is well documented on the Common.Logging website. If you want to append to a file or something else, see the log4net docs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文