渡された(任意のタイプの)メソッドの実行時間を測定することを目的として、非常に単純なユーティリティクラスを作成しています。
私の場合Membership.ValidateUser(model.UserName, model.Password)
は bool を返すため、例外が発生します。
可能であれば、このタイプのユーティリティ クラスと、それを修正する方法に関するコードのサンプルを書きたいと思います。アクションの代わりにダイナミックを使用するのは理にかなっていますか?
Tracing.Log(Membership.ValidateUser(model.UserName, model.Password), "Membership.ValidateUser");
public static class Tracing
{
public static void Log(Action action, string message)
{
// Default details for the Log
string sSource = "TRACE";
string sLog = "Application";
// Create the Log
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
// Measure time Elapsed for an Action
Stopwatch stopwatch = Stopwatch.StartNew();
action();
stopwatch.Stop();
TimeSpan timeElapsed = stopwatch.Elapsed;
// Write the Log
EventLog.WriteEntry(sSource, "TIME-ELAPSED: " + timeElapsed .ToString() + message, EventLogEntryType.Warning, 234);
}
}