Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. [HttpGet]
  2. [Route( "page" )]
  3. public async Task<IActionResult> GetPage(
  4. int? page, int? size,
  5. CancellationToken ct)
  6. {
  7. try {
  8. var response = await _mailService.GetPageAsync( page, size, ct: ct );
  9. return Respond( response ); // Turn service response into HTTP response
  10. }
  11. catch (OperationCanceledException) {
  12. // When reaching here, Exception already logged
  13. // If it should be cancelled
  14. if (ct.IsCancellationRequested) {
  15. // Empty result
  16. return new EmptyResult();
  17. }
  18. else {
  19. // Else raise again
  20. throw; // Never reached
  21. }
  22. }
  23. }
  24.  
  25. try {
  26. page = query.ToListAsync( ct );
  27. catch(TaskCanceledException){
  28. // When reaching here, Exception already logged
  29. return null;
  30. }
  31.  
  32. var logConfig = new LoggerConfiguration()
  33. .MinimumLevel.Debug()
  34. .Enrich.FromLogContext();
  35. // Add Sinks
  36.  
  37. // Create Logger
  38. Log.Logger = logConfig.CreateLogger();
  39.  
  40.  
  41. // Configure()
  42. loggerFactory.AddSerilog();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement