Created
January 8, 2020 09:43
-
-
Save kadukf/1b5a835c1169cde3318a56a3723f7c71 to your computer and use it in GitHub Desktop.
Sample controller with logging and using scopes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Route("api/[controller]")] | |
[ApiController] | |
public class ValuesController : ControllerBase | |
{ | |
private readonly ILogger<ValuesController> _logger; | |
public ValuesController(ILogger<ValuesController> logger) | |
{ | |
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); | |
} | |
// GET api/values/some_name | |
[HttpGet("{userId}")] | |
public ActionResult<string> Get(string userId) | |
{ | |
using (_logger.BeginScope("my scope")) | |
{ | |
_logger.LogInformation("Handling sample request"); | |
return "Hello " + userId; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment