Enterprise Library 5 Logging块抛出SynchronizationLockException

时间:2010-10-27 16:27:45

标签: entity-framework enterprise-library

Global.asax.cs内,我得到: 从非同步代码块

调用对象同步方法
protected void Application_Start()
    {
        InitContainer();

        AreaRegistration.RegisterAllAreas();

        RegisterRoutes(RouteTable.Routes);

        ControllerBuilder.Current.SetControllerFactory(typeof(UnityControllerFactory));
        CheckForAndMinify();
        Logger.Write("test"); //exception
       // if (System.Diagnostics.Debugger.IsAttached)
           // MvcContrib.Routing.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
        //RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);

    }

环境:

  • Asp.net Mvc2
  • VS2010
  • Windows7 Enterprise 64bit
  • Unity框架在此日志记录代码之前启动

相关的web.config条目:

<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true"/>

    <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
    <listeners>
        <add name="GeneralRolling" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" fileName="~\App_Data\rolling2.log" formatter="Text Formatter" rollInterval="Day" rollSizeKB="2056" maxArchivedFiles="2" filter="Warning"/>
        <add name="EspionageRolling" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" fileName="~\App_Data\EspRolling.log" formatter="Text Formatter" rollInterval="Day" rollSizeKB="1024" maxArchivedFiles="2" traceOutputOptions="DateTime"/>
        <add name="SnapshotRolling" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" fileName="~\App_Data\SnapRolling.log" formatter="Text Formatter" rollInterval="Day" rollSizeKB="1024" maxArchivedFiles="2" traceOutputOptions="DateTime"/>
    </listeners>
    <formatters>
        <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" template="Title:{title}{newline}&#xA;Category: {category}{newline}&#xA;Message: {message}{newline}&#xA;Timestamp: {timestamp}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}" name="Text Formatter"/>
    </formatters>
    <categorySources>
        <add switchValue="All" name="General">
            <listeners>
                <add name="GeneralRolling"/>
            </listeners>
        </add>
        <add switchValue="All" name="Espionage">
            <listeners>
                <add name="EspionageRolling"/>
            </listeners>
        </add>
        <add switchValue="All" name="SnapShot">
            <listeners>
                <add name="SnapshotRolling"/>
            </listeners>
        </add>
    </categorySources>
    <specialSources>
        <allEvents switchValue="All" name="All Events">
            <listeners>
                <add name="GeneralRolling"/>
            </listeners>
        </allEvents>
        <notProcessed switchValue="All" name="Unprocessed Category"/>
        <errors switchValue="All" name="Logging Errors &amp; Warnings">
            <listeners>
                <add name="GeneralRolling"/>
            </listeners>
        </errors>
    </specialSources>
</loggingConfiguration>

我正在尝试确保记录器在应用程序启动时正常工作,以便应用程序无法启动,看起来正确,然后在第一次尝试记录某些内容时立即死亡。

日志记录xml配置没有改变,它以前工作。主要的变化是添加Unity,并将应用程序从linq切换到sql。我还没有确认此代码是否在部署环境中有效,因此它可能由于某种原因在适当的环境中工作,而不是在本地。

1 个答案:

答案 0 :(得分:0)

如果您在Visual Studio之外运行应用程序,它会崩溃吗?您所看到的是Unity的一个问题,以及它如何创建单例。如果将vs设置为仅显示未处理的用户异常,那么您将不再看到它。我刚才有同样的问题。这是迟钝的。我在Enterprise Library 4中没有看到这个,只是在5中。