使用Ninject.Extensions.Logging.Log4Net运行项目时“违反了继承安全规则”?

时间:2013-11-20 19:12:43

标签: c# .net xml ninject ninject-extensions

我正在处理一个应用程序,其中包含对log4netNinjectNinject.Extensions.LoggingNinject.Extensions.Logging.Log4net的引用。当我尝试运行应用程序时,我收到一个例外:

{"Inheritance security rules violated by type: 'Ninject.Extensions.Logging.LoggerModuleBase'. Derived types must either match the security accessibility of the base type or be less accessible.":"Ninject.Extensions.Logging.LoggerModuleBase"}

我对Ninject和日志记录扩展完全不熟悉。我见过several suggestions,其中包括:

[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]

但我没有看到实际问题是什么以及为什么我需要修改发布源代码以与我的应用程序合并。因此,我假设我做错了。问题可能是什么?

有关详细信息,该应用程序是针对.Net 4而不是.Net 4客户端配置文件构建的,我在构建扩展时尝试同时定位客户端配置文件和完整的.Net 4框架,但两者都没有起作用。

我正在使用提供的.sln文件(而不是nAnt构建文件)构建扩展的发行版本。可以在Github上找到扩展项目。

我正在运行Visual Studio 2010。

我的内核是这样构建的:

private static StandardKernel kernel;
public static StandardKernel Kernel
{
    get
    {
        return kernel;
    }
}

public static void BuildKernel()
{
    var settings = new NinjectSettings
    {
        LoadExtensions = false
    };

    var modules = new INinjectModule[]
    {
        new MainModule(),
        new Log4NetModule()
    };

    kernel = new StandardKernel(settings, modules);
}

我的log4net配置相当基本,但这是我的完整app.Config文件:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="lib" />
    </assemblyBinding>
  </runtime>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>
  <log4net>
    <appender name="BasicAppender" type="log4net.Appender.FileAppender">
      <threshold value="Warn"/>
      <file value="Logs/errorlog.txt"/>
      <appendToFile value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <header value="[Basic Appender]&#13;&#10;" />
        <footer value="[Basic Appender]&#13;&#10;" />
        <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />
      </layout>
    </appender>
    <root>
      <level value="ALL" />
      <appender-ref ref="BasicAppender" />
    </root>
  </log4net>
</configuration>

1 个答案:

答案 0 :(得分:1)

我仍然不确定导致错误的原因,但是通过Nuget更新到可用的版本修复了它。 https://www.nuget.org/packages/Ninject.Extensions.Logging.Log4net/3.0.1