500 오류가 발생할 때마다 스택 추적을 기록하기 위해 로그 수준을 높이려면 어떻게해야합니까?스택 추적을 기록하는 방법?
내 코드 또는 IIS의 사이트 구성에서 수행 할 작업이 있습니까?
500 오류가 발생할 때마다 스택 추적을 기록하기 위해 로그 수준을 높이려면 어떻게해야합니까?스택 추적을 기록하는 방법?
내 코드 또는 IIS의 사이트 구성에서 수행 할 작업이 있습니까?
코드 뒤에 Exception
을 붙잡고 StackTrace
속성에 액세스하면됩니다.
try
{
//your code
}
catch(Exception ex)
{
Console.WriteLine(
"\nStackTrace ---\n{0}", ex.StackTrace);
}
이렇게하면 스택 추적을 콘솔 창에 씁니다. 당신은 그래서 당신이 원하는 것을 할 것 두 가지를 함께 다음 퍼팅이
public static void LogException(Exception exc, string source)
{
// Get the absolute path to the log file
string logFile = "App_Data/ErrorLog.txt";
logFile = HttpContext.Current.Server.MapPath(logFile);
// Open the log file for append and write the log
StreamWriter sw = new StreamWriter(logFile, true);
sw.WriteLine("********** {0} **********", DateTime.Now);
sw.Write("Exception Type: ");
sw.WriteLine(exc.GetType().ToString());
sw.WriteLine("Exception: " + exc.Message);
sw.WriteLine("Source: " + source);
sw.WriteLine("Stack Trace: ");
if (exc.StackTrace != null)
{
sw.WriteLine(exc.StackTrace);
sw.WriteLine();
}
sw.Close();
}
처럼 뭔가를 할 수있는 로그 텍스트 파일에 메시지를 작성하기 위해
:
try
{
//your code
}
catch(Exception ex)
{
string logFile = "App_Data/ErrorLog.txt";
logFile = HttpContext.Current.Server.MapPath(logFile);
// Open the log file for append and write the log
StreamWriter sw = new StreamWriter(logFile, true);
sw.WriteLine("********** {0} **********", DateTime.Now);
sw.Write("Exception Type: ");
sw.WriteLine(exc.GetType().ToString());
sw.WriteLine("Exception: " + ex.Message);
sw.WriteLine("Source: " + source);
sw.WriteLine("Stack Trace: ");
if (exc.StackTrace != null)
{
sw.WriteLine(ex.StackTrace);
sw.WriteLine();
}
sw.Close();
}
IIS가 이미이 로그를 기록하고 있습니다. IIS 서버의 이벤트 로그를 살펴보십시오.
ASP.NET Health Monitoring을 사용하여 원하는대로 캡처하여 보낼 수 있지만 ELMAH와 같은 더 우수한 예외 처리기로 작업하고 싶을 수도 있습니다.