I wanted to write a Visual Studio Macro or something similar which can fetch function name and insert into preset location in the error report part. It's clearer if you look at the example
Class SampleClass
{
public void FunctionA()
{
try
{
//Do some work here
}
catch (Exception ex)
{
Logger.WriteLine(LogLevelEnum.Error, "SampleClass", "FunctionA Failed");
Logger.WriteLine(LogLevelEnum.Error, "FunctionA", ex.ToString());
}
finally
{
}
}
}
So, I followed the similar pattern of most of the critical functions of my common library. I would like to be able to insert "FunctionA" into the logging section during pre-built so that I don't have to remember to type in the right name or forgetting to rename it after copy and paste. Either that can be invoke manually from the toolbar or via shortcut key.
So, where should I start?
NOTE: I'm considered intermediate in .Net, been writting in C# and VB for more than 3 years, but I'm fresh on Macro, don't mind to learn though. Don't worry about the code itself and the exception, this is just an example.
EDIT: Thanks Ovidiu Pacurar and cfeduke. What I wanted here was a one off way to change-and-forget. PostSharp will incur overhead on every one of those function, even when exception is not thrown. Digging from the stacktrace is feasible, but at some point I would also like to just log "FunctionA Failed" without spending too much processing in getting the stacktrace. Further more, if the library is obfuscated, the stacktrace would be cryptic.
Actually there was another need for this feature, which I forgot to mention earlier. When the library is ready to be delivered, I would want to change all the function name into function code, "FunctionA" might be "0001", by referring to a table, so as to solve the "obfuscated" log problem.