在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);
}
环境:
相关的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}
Category: {category}{newline}
Message: {message}{newline}
Timestamp: {timestamp}{newline}
Priority: {priority}{newline}
EventId: {eventid}{newline}
Severity: {severity}{newline}
Machine: {localMachine}{newline}
App Domain: {localAppDomain}{newline}
ProcessId: {localProcessId}{newline}
Process Name: {localProcessName}{newline}
Thread Name: {threadName}{newline}
Win32 ThreadId:{win32ThreadId}{newline}
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 & Warnings">
<listeners>
<add name="GeneralRolling"/>
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
我正在尝试确保记录器在应用程序启动时正常工作,以便应用程序无法启动,看起来正确,然后在第一次尝试记录某些内容时立即死亡。
日志记录xml配置没有改变,它以前工作。主要的变化是添加Unity,并将应用程序从linq切换到sql。我还没有确认此代码是否在部署环境中有效,因此它可能由于某种原因在适当的环境中工作,而不是在本地。
答案 0 :(得分:0)
如果您在Visual Studio之外运行应用程序,它会崩溃吗?您所看到的是Unity的一个问题,以及它如何创建单例。如果将vs设置为仅显示未处理的用户异常,那么您将不再看到它。我刚才有同样的问题。这是迟钝的。我在Enterprise Library 4中没有看到这个,只是在5中。