简体   繁体   English

Spring.Net。 ContextRegistry.GetContext()异常,无法配置Common.Logging

[英]Spring.Net. ContextRegistry.GetContext() exception, cannot configure Common.Logging

I cannot get the IApplication context for my console app 我无法获得控制台应用程序的IApplication上下文

I get an exception with this detail: The type initializer for 'Spring.Context.Support.ContextRegistry' threw an exception. 我得到了一个如此详细的异常: The type initializer for 'Spring.Context.Support.ContextRegistry' threw an exception.

With inner exception: Could not configure Common.Logging from configuration section 'common/logging 有内部异常: Could not configure Common.Logging from configuration section 'common/logging

There's clearly something basic I've not hooked up, but I'm not sure what. 很明显,我还没有了解一些基本的知识,但是我不确定是什么。

using Spring.Context;
using Spring.Context.Support;

namespace ConsoleApplication4
{
   class Program
   {
       static void Main(string[] args)
       {
          IApplicationContext ctx = ContextRegistry.GetContext();
       }
   }
}

And my app.config looks like this: 我的app.config看起来像这样:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="spring">
      <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
      <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
    </sectionGroup>
  </configSections>
  <spring>
    <context>
      <resource uri="config://spring/objects"/>
    </context>
    <objects xmlns="http://www.springframework.net">
      <description>An  example that demonstrates simple IoC features.                  </description>
    </objects>
  </spring>
</configuration>

The type initializer for 'Spring.Context.Support.ContextRegistry' threw an exception “ Spring.Context.Support.ContextRegistry”的类型初始值设定项引发了异常

This is valueable information and Spring.net is really good at providing additional information. 这是有价值的信息,Spring.net确实擅长提供其他信息。 Whenever Spring.net throws something, be sure to read the InnerException . 每当Spring.net抛出异常时,请务必阅读InnerException

WHen I edit my config I get the messages: Could not find schema information for the attribute #. 当我编辑配置时,得到以下消息:找不到属性#的架构信息。 for # = 'uri', 'context', 'resource' and 'spring' 对于#='uri','context','resource'和'spring'

This is normal if you didn't install the schemas. 如果您没有安装模式,这是正常的。 You can download the schemas at their site and find additional information in their docs . 您可以在其站点上下载这些架构 ,并在其文档中找到其他信息 Please note that this is optional and spring runs without those schemas. 请注意,这是可选的,spring运行时没有这些模式。

Spring.Net uses Common Logging as facility for logging, you have to add the logging configuration to your app.config and the proper library to the referenced assemblies. Spring.Net使用通用日志记录作为记录工具,您必须将记录配置添加到app.config ,并将适当的库添加到引用的程序集中。

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

  <common>
    <logging>
      <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
        <arg key="level" value="DEBUG" />
        <arg key="showLogName" value="true" />
        <arg key="showDataTime" value="true" />
        <arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
      </factoryAdapter>
    </logging>
  </common>
</configuration>

http://netcommon.sourceforge.net/docs/1.2.0/reference/html/logging.html#logging-declarative-config http://netcommon.sourceforge.net/docs/1.2.0/reference/html/logging.html#logging-declarative-config

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我在调用ContextRegistry.GetContext()时从Spring.NET中获得异常? - Why am I getting an exception raised from Spring.NET on the call to ContextRegistry.GetContext()? Spring.NET - 不建议使用ContextRegistry.GetContext? - Spring.NET - using ContextRegistry.GetContext is not advised? Common.Logging 配置异常 - Common.Logging config exception 在Common.Logging中配置布局 - Configure layout in Common.Logging log4net(common.logging)错误异常 - log4net (common.logging) erroneous exception 无法从ContextRegistry.GetContext()获取WebApplicationContext对象:未定义“ Web”协议的资源处理程序 - Can't get WebApplicationContext object from ContextRegistry.GetContext(): Resource handler for the 'web' protocol is not defined Common.Logging.dll中的异常:无法从配置节“ common / logging”中获取Common.Logging的配置 - Exception in Common.Logging.dll: Failed obtaining configuration for Common.Logging from configuration section 'common/logging' Spring.Rest和Common.Logging 3.0兼容性问题 - Spring.Rest and Common.Logging 3.0 Compatability issues Common.Logging 包更新与 Log4Net 不兼容 - Common.Logging package update not compatible with Log4Net 使用Common.Logging与Asp.net MVC和Castle Windsor - Using Common.Logging with Asp.net MVC and Castle Windsor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM