我正在为我的应用程序编写错误记录器。基本上,我感兴趣的是在处理异常时,从我的日志类中调用一个名为CreateLogEntry(...)的函数。我的想法是希望CreateLogEntry(...)知道它是从方法BadFunction(...)中调用的,并将其参数作为日志过程的一部分检索出来。
现在我已经做了一些功课(虽然可能还不够:S),并且确定我的解决方案在System.Reflection中。我已经找到了一些关于如何枚举类中所有函数的示例(http://www.csharp-examples.net/get-method-names/)。但是否有可能获取创建引发该异常的函数名称?
例如(我得到的):
非常感谢您的帮助。
现在我已经做了一些功课(虽然可能还不够:S),并且确定我的解决方案在System.Reflection中。我已经找到了一些关于如何枚举类中所有函数的示例(http://www.csharp-examples.net/get-method-names/)。但是否有可能获取创建引发该异常的函数名称?
例如(我得到的):
public string GetCurrentMode()
{
string currentMode = "";
try
{
currentMode = _host.Mode.ToString();
}
catch(Exception ex)
{
Common.MorpheeException me = new Common.MorpheeException();
me.MethodName = "GetCurrentMode";
me.NameSpace = "MorpheeScript";
me.ErrorNumber = 0;
me.ErrorDescription = ex.Message;
me.StackTrace = ex.StackTrace;
throw new FaultException<Common.MorpheeException>(me);
}
return currentMode;
}
我希望你能为我提供以下内容:
public string GetCurrentMode()
{
string currentMode = "";
try
{
currentMode = _host.Mode.ToString();
}
catch(Exception ex)
{
Common.MorpheeException me = new Common.MorpheeException(ex);
// Here me should know that it is called from GetCurrentMode() and
// retrieve the parameters if there are any
throw new FaultException<Common.MorpheeException>(me);
}
return currentMode;
}
非常感谢您的帮助。