これに 1 日を費やしたので、解決策を共有したいと思います。上記の Myster のソリューションと非常によく似ていますが、違いは、次のように、リクエスト サーバー変数の代わりに elmah で使用されるエラー オブジェクトを変更することです。
public static void LogError(Exception e, IDictionary<string, string> customFields = null)
{
var logger = ErrorLog.GetDefault(HttpContext.Current);
customFields = customFields ?? new Dictionary<string, string>();
// Used to tell elmah not to log this twice (See global.asax)
e.Data.Add("Logged", true);
var error = new Error(e, HttpContext.Current);
customFields.ForEach(pair => error.ServerVariables.Add(pair.Key, pair.Value));
logger.Log(error);
}
次に、アプリケーションに応じて logger.LogError を呼び出します。
mvc カスタム エラー フィルターを追加します ( http://maheshde.blogspot.ca/2012/09/error-handing-with-mvc-using-custom.html )
webforms は global.asax の Application_Error を上書きします
次に、global.asax の最後の手順として、既にログに記録されているエラーをすべて破棄します。
public void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
{
if (e.Exception.Data.Contains("Logged"))
{
if (e.Exception.Data["Logged"].Equals(true)) e.Dismiss();
}
}