I am developing an application in ASP.Net 4.0 with C# where I am doing logging and tracing using Microsoft's Enterprise Lib. My problem is that almost in every function , as per my company guidline, where there is interaction with database or some critical business rules , use tracing, in this format.
try
{
_traceLog.clear();
_traceLog.AppendLine("XYZ method started: XYZ()");
_traceLog.AppendLine("XYZ method completed: XYZ()");
}
catch(Exception ex)
{
_userException.CreateExceptionLog(ex);
}
finally
{
_userException.CreateTraceLog(_traceLog.ToString());
}
So what i want is to convert it as a code snippet that will automatically detect the current method, say in above case we have XYZ().
Please help me. Also tell me the way to add this to intellisense. Right now i am able create .snippet file and uses insert snippet from context menu.
UPdate
I think i am not clear to you guys. Let me make more clear. i have an code snippet
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2010/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>
TL
</Title>
</Header>
<Snippet>
<Code Language="CSharp">
<![CDATA[ try
{
_traceLog.Clear();
_traceLog.AppendLine(""); // here in side the append line i want to get name of method under which i am placing code snippet.
_traceLog.AppendLine("");
}
catch (Exception ex)
{
_userExceptionLog.CreateExceptionLog(ex);
}
finally
{
_userExceptionLog.CreateTraceLog(_traceLog.ToString());
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
For example if my method is
void XYZ()
{
// when i insert snippet here , the snippet will automatically detect
that this snippet is going to be placed under XYZ function.
try
{
_traceLog.Clear();
_traceLog.AppendLine("XYZ started: XYZ()");
// here in side the append line i want to get name of method under which i am placing code snippet.
_traceLog.AppendLine("XYZ completed: XYZ()");
}
catch (Exception ex)
{
_userExceptionLog.CreateExceptionLog(ex);
}
finally
{
_userExceptionLog.CreateTraceLog(_traceLog.ToString());
}
}
Is this possible? or I have to enter it manually or any other short way?
Application_Errorevent of the global.asax of we ASP.NET web application).