문제

Elmah (훌륭함)를 사용하는 경우 예외에 추가 한 추가 정보를 볼 수 있습니다.

예를 들어

Exception ex = new Exception("New exception to use ErrorSignal functionality");
ex.Data.Add("ExtraInfo", "Here is some extra information i would like to be displayed.");
ErrorSignal.FromCurrentContext().Raise(ex);    

Elmah.axd의 예외를 보면 "extrainfo"키와 값 정보가 표시되지 않는 것 같습니다.

도움이 되었습니까?

해결책

아니요, 현재 1.x 릴리스로 추가 정보를 볼 수 없습니다.

다른 팁

내 솔루션은 SO와 같은 서버 변수 컬렉션에 정보를 추가하는 것이 었습니다.

var context = HttpContext.Current;
context.Request.ServerVariables["ERROR_CALLING_WEBSERVICE_URI"] = uri;
Elmah.ErrorLog.GetDefault(context).Log(new Error(e, context))

예, 나는 이것이 해킹이라고 생각합니다.
소량의 추가 데이터의 경우 @Roma가 제안한 오류를 캡슐화하는 것을 고려하십시오.
그러나이 방법은 '캡슐화 된 오류 메시지'에 넣기에 너무 많은 정보가있는 경우 특히 유용합니다.

돌아 다니는 간단한 방법은 오류를 캡슐화하는 것입니다. 외부 오류에는 사용자 정의 메시지가 포함됩니다.

string msg = "my custom error message";

ErrorSignal.FromCurrentContext().Raise(
               new Elmah.ApplicationException(msg,ex));

좋아, 그래서 나는 이것을 지금 너무 오랫동안 포함시키기를 기다리고 있었고, 그것의 포크를 만들고 직접 기능을 포함하기로 결정했습니다.

여기에서 찾을 수 있습니다. https://github.com/boena/elmah-with-custom-data

Elmah는 Tostring () 메소드를 사용하여 예외 세부 정보를 얻습니다. 사용자 정의 예외 toString () 메소드를 무시하면 다음과 같이 작동합니다.

sample exception in elmah

내 예외 클래스 :

public class MyCustomException : Exception
{
    public string CustomProperty { get; set; }

    public MyCustomException(string message, string customProperty): base(message)
    {
        this.CustomProperty = customProperty;
    }

    public override string ToString()
    {
        var result = base.ToString();
        var propertyData = String.Format("CustomProperty: {0}", this.CustomProperty);

        return result.Insert(
            result.IndexOf(Environment.NewLine),
            Environment.NewLine + propertyData
            );
    }
}

글쎄,이 일을하면서 하루를 보냈으며 솔루션을 공유 할 것이라고 생각했습니다. 위의 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();
    }
}

오픈 소스이므로 프로젝트를 잡고 자신의 목적을 위해 Elmah를 사용자 정의 할 수 있습니다.

http://code.google.com/p/elmah/

MSSQL을 사용하는 경우

  • sqlerrorlog.cs를 살펴보십시오

  • sqlserver.sql 자체 데이터베이스를 생성하려면

나는 똑같은 일을하고 있지만 무작위로 생성 된 "오류 코드"열을 추가해야하며 예외 데이터를 사용하여 일반적으로 Uber 대형 XML에있는 모든 사용자 정의, 세션, 양식, 쿠키 정보를 추적 할 것입니다. 필드. 아직 확실하지 않은 JSON으로 변경할 수 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top