実際には、アプリケーションがc#で処理するメソッドを持つような方法でデータを記録したいのですが、エラーがある場合はエラーコンテンツも記録する必要があります。問題は、どこのメソッドを呼び出すか、すべてのメソッドの内部でログメソッドを呼び出すことですか?私は200近い方法を持っているからです。どこでC#のすべてのメソッドのキャッチまたは内部のロギングメソッドを呼び出すのですか?
私はこのようなコードを書いた:
public static bool Logging(System.Reflection.MethodBase methodInfo)
{
var fullMethodName = methodInfo.DeclaringType.FullName + "." + methodInfo.Name;
if (error_flag == false)
{
using (StreamWriter outputFile = new StreamWriter(path + @"\log.txt", true))
{
outputFile.WriteLine(fullMethodName + ": OK");
}
}
else
{
using (StreamWriter outputFile = new StreamWriter(path + @"\log.txt", true))
{
outputFile.WriteLine("\n\n --> Error in : " + fullMethodName);
}
}
return true;
}
//Logging Method 2
public static bool WriteErrorLog(Exception ErrorMessage)
{
using (StreamWriter outputFile = new StreamWriter(path + @"\log.txt", true))
{
outputFile.WriteLine("{0} Exception caught.", ErrorMessage);
}
return true;
}
を、私はからこれらのメソッドを呼び出す必要があります?
可能な重複[log4netのログすべての未処理のアプリケーションエラー](http://stackoverflow.com/questions/1367967/log4net-log-all-unhandled-application-errors)私は、スタックトレースを取得することができます – Martheen