Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dmarlow
Created February 2, 2015 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmarlow/a7f65342d55630dcde2c to your computer and use it in GitHub Desktop.
Save dmarlow/a7f65342d55630dcde2c to your computer and use it in GitHub Desktop.
var sw = Stopwatch.StartNew();
var msg = new StringBuilder();
bool error = false;
try
{
msg.AppendFormat("Doing something with xyz {0}", blah);
if (!string.IsNullOrEmpty(value))
{
// do something here
msg.AppendFormat(" {0} --> {1}.", something, value);
}
else
{
msg.Append(" null str.");
}
if (something)
{
msg.Append(" blah.");
// do more stuff
}
return exValue;
}
catch (Exception e)
{
// Either throw or append and set error = true.
}
finally
{
sw.Stop();
if (error)
{
Log.ErrorFormat("{0} {1} ms", msg, sw.ElapsedMilliseconds);
}
else
{
Log.DebugFormat("{0} {1} ms", msg, sw.ElapsedMilliseconds);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment