代码之家  ›  专栏  ›  技术社区  ›  Saajid Ismail

发生异常ASP.Net在共享主机上使用Log4net的MVC应用程序

  •  0
  • Saajid Ismail  · 技术社区  · 16 年前

    我有一个网站是用ASP.NetMVC,并使用Log4net进行异常日志记录。直到大约4小时前,这个网站一直运行良好。我们在过去两周内没有对网站进行任何更改。这个网站自从我们1个月前建立以来一直运行得很顺利。该网站是在我们的ISP托管共享托管帐户。

    这是我们收到的例外情况:

    [FormatException: String was not recognized as a valid Boolean.]
       log4net.Core.LoggerManager.RegisterAppDomainEvents() +0
       log4net.Core.LoggerManager..cctor() +33
    
    [TypeInitializationException: The type initializer for 'log4net.Core.LoggerManager' threw an exception.]
       log4net.Core.LoggerManager.GetLogger(Assembly repositoryAssembly, String name) +0
       log4net.LogManager.GetLogger(Assembly repositoryAssembly, String name) +8
       log4net.LogManager.GetLogger(String name) +20
       i3t.LcaWeb.View.MvcApplication..cctor() in Global.asax.cs:17
    
    [TypeInitializationException: The type initializer for 'i3t.LcaWeb.View.MvcApplication' threw an exception.]
       i3t.LcaWeb.View.MvcApplication..ctor() +0
       ASP.global_asax..ctor() in App_global.asax.fqjmwqjv.0.cs:0
    
    [TargetInvocationException: Exception has been thrown by the target of an invocation.]
       System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
       System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +86
       System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +230
       System.Activator.CreateInstance(Type type, Boolean nonPublic) +67
       System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +1051
       System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +111
       System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +215
       System.Web.HttpApplicationFactory.FireApplicationOnStart(HttpContext context) +8878568
       System.Web.HttpApplicationFactory.EnsureAppStartCalled(HttpContext context) +136
       System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +92
       System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +289
    

    log4net.ILog 正在创建:

    public class MvcApplication : System.Web.HttpApplication
    {
        private static log4net.ILog log = log4net.LogManager.GetLogger("global.asax");
    
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
            routes.MapRoute(
                "Home.aspx",
                "",
                new { action = "Index", controller = "Home" }
            );
    

    这个问题不会在测试中发生,我们无法重现。我已经删除了现场网站上的所有文件,并重新上传,以防有东西被破坏,但这并没有解决问题。

    有什么解决这个问题的线索吗?

    2 回复  |  直到 16 年前
        1
  •  0
  •   Michael Keane Galloway    12 年前

    我也有类似的问题。在我的情况下,我意外地在Web.config文件作为不是布尔值的东西。

    <appender name="XYLogger" type="log4net.Appender.RollingFileAppender">
        <file value="App_Data\logging\xymaps.log" />
        <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
        <appendToFile value="some-file-name"/>
        <rollingStyle value="Size" />
        <maxSizeRollBackups value="2" />
        <maximumFileSize value="2MB" />
        <staticLogFileName value="true" />
        <layout type="log4net.Layout.PatternLayout">
            <param name="ConversionPattern" value="%d [%t] %-tp %c %m%n" />
        </layout>
    </appender>
    

    我搞错了 <appendToFile> 作为指定记录器应附加到的文件名的标记。相反,它应该读到 <appendToFile value="true" /> . 如果有人碰到他们的问题,我建议他们再检查一次Web.config文件对于具有错误值的布尔字段。

        2
  •  -1
  •   Sunil Chowgale    15 年前

    LogManager.GetLogger()需要用于日志记录的类的名称,而不是全局.asax,它是文件的名称。请仅使用“Global”作为参数LogManager.GetLogger().