Skip to content

Instantly share code, notes, and snippets.

@otienoelvis
Created August 13, 2023 12:03
Show Gist options
  • Save otienoelvis/33463a532edc258cedb0b0fd8af214d3 to your computer and use it in GitHub Desktop.
Save otienoelvis/33463a532edc258cedb0b0fd8af214d3 to your computer and use it in GitHub Desktop.
TestController.cs
using Microsoft.AspNetCore.Mvc;
namespace ErrorNotification.Controllers;
[Route("api/[controller]/[action]")]
[ApiController]
public class TestController : ControllerBase
{
private readonly ILogger<TestController> _logger;
public TestController(ILogger<TestController> logger)
{
_logger = logger;
}
[HttpGet]
public async Task<IActionResult> TestOkay()
{
try
{
_logger.LogInformation("Testing Okay");
return Ok();
}
catch (Exception e)
{
_logger.LogError(e, e.Message);
throw;
}
}
[HttpGet]
public async Task<IActionResult> TestNotOkay()
{
try
{
throw new ArgumentNullException(nameof(TestNotOkay));
}
catch (Exception e)
{
_logger.LogError(e, e.Message);
throw;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment