簡體   English   中英

在異常日志中拋出異常

[英]Exception thrown inside Exceptional logging

我用Exceptional代替Elmah,但是有問題。 如果在我的Web項目中引發了異常,或者錯誤是404(找不到路徑'/ blah / blah'的控制器或未實現IController),則此方法工作正常。

但是,如果從我引用的項目之一(而不是Web項目)中引發異常,則嘗試記錄時Exceptional引發錯誤。 以下錯誤和堆棧跟蹤僅顯示在控制台中。 該錯誤此時已被吞沒,並且未在任何地方記錄。

開源的優點之一是,我可以看到引發異常的代碼,但不知道為什么……

Error.cs (第107、135、126行)

Exception thrown: 'System.ArgumentException' in Cms.Services.dll
'w3wp.exe' (CLR v4.0.30319: /LM/W3SVC/1/ROOT/wssp-18-131152201224510365): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Web.HttpRequest.CalcDynamicServerVariable(DynamicServerVariable var)
   at System.Web.HttpServerVarsCollectionEntry.GetValue(HttpRequest request)
   at System.Web.HttpServerVarsCollection.GetServerVar(Object e)
   at System.Web.HttpServerVarsCollection.Get(Int32 index)
   at System.Web.HttpServerVarsCollection.GetValues(Int32 index)
   at System.Collections.Specialized.NameValueCollection.Add(NameValueCollection c)
   at StackExchange.Exceptional.Error.<>c__DisplayClass22_0.<SetContextProperties>b__0(Func`2 getter) in C:\BuildAgent\work\d20fce4a5bb47bd3\StackExchange.Exceptional\Error.cs:line 126
   at StackExchange.Exceptional.Error.SetContextProperties(HttpContext context) in C:\BuildAgent\work\d20fce4a5bb47bd3\StackExchange.Exceptional\Error.cs:line 135
   at StackExchange.Exceptional.Error..ctor(Exception e, HttpContext context, String applicationName) in C:\BuildAgent\work\d20fce4a5bb47bd3\StackExchange.Exceptional\Error.cs:line 107
   at StackExchange.Exceptional.ErrorStore.LogException(Exception ex, HttpContext context, Boolean appendFullStackTrace, Boolean rollupPerServer, Dictionary`2 customData, String applicationName) in C:\BuildAgent\work\d20fce4a5bb47bd3\StackExchange.Exceptional\ErrorStore.cs:line 611

我正在這樣注冊Exceptional:

  string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MyApp"].ConnectionString;
  ErrorStore.Setup("MyApp", new SQLErrorStore(connectionString));

這是我的web.config中唯一的代碼:

<modules runAllManagedModulesForAllRequests="true">
  <add name="ErrorStore" type="StackExchange.Exceptional.ExceptionalModule, StackExchange.Exceptional" />
</modules>

我終於找到了問題。 下面的代碼是我用來從應用程序中注銷用戶的代碼。

var authenticationManager = HttpContext.GetOwinContext().Authentication;
authenticationManager.SignOut();
authenticationManager.User = new ClaimsPrincipal();

當第三行執行並將用戶設置為新的ClaimsPrinciple ,它將刪除以下3個值(AUTH_TYPE,AUTH_USER,REMOTE_USER),並將它們在System.Web.HttpContext.Current.Request.ServerVariables對象內設置為null。鍵仍然在對象內部。

因此,在該行之后引發的任何異常都不會由Stackexchange.Exceptional記錄,因為它試圖讀取這些值,然后引發System.NullReferenceException。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM