Skip to content

Instantly share code, notes, and snippets.

@hudo
Created October 14, 2015 21:52
Show Gist options
  • Select an option

  • Save hudo/39ab677888c5c78a3735 to your computer and use it in GitHub Desktop.

Select an option

Save hudo/39ab677888c5c78a3735 to your computer and use it in GitHub Desktop.
Logger in controller
public class OrderController : Controller
{
// constructor and other dependent objects
[HttpPost, ValidateAntiForgeryToken]
public ActionResult Pay(PayRequest request)
{
var order = _repository.Get(request.OrderId);
_logger.InfoOperations("Trying to pay the order ", payRequest)
var stopwatch = new Stopwatch();
stopwatch.Start();
try
{
_paymentService.SendForPayment(request);
}
catch(Exception e)
{
_logger.ErrorOperation("Error processing payment request", e);
}
finally
{
stopwatch.Stop();
_logger.DebugPerformance("Payment service executed in " + stopwatch.ElapsedMilisecunds + "ms");
}
return Redirect("Index");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment