-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathIndex.cshtml.cs
33 lines (28 loc) · 1007 Bytes
/
Index.cshtml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace AspNet6.Pages
{
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
}
public void OnGet()
{
LogSampleLogs();
}
private void LogSampleLogs()
{
var structuredData = new StructuredData();
var simpleData = "This is a string.";
_logger.LogTrace("Here's a Verbose message.");
_logger.LogDebug("Here's a Debug message. Only Public Properties (not fields) are shown on structured data. Structured data: {@sampleData}. Simple data: {simpleData}.", structuredData, simpleData);
_logger.LogInformation(new Exception("Exceptions can be put on all log levels"), "Here's an Info message.");
_logger.LogWarning("Here's a Warning message.");
_logger.LogError(new Exception("This is an exception."), "Here's an Error message.");
_logger.LogCritical("Here's a Fatal message.");
}
}
}