-
Notifications
You must be signed in to change notification settings - Fork 25.3k
/
Index.cshtml.cs
84 lines (71 loc) · 2.82 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Configuration;
namespace ChangeTokenSample.Pages
{
public class IndexModel : PageModel
{
private readonly IConfiguration _config;
private readonly IConfigurationMonitor _monitor;
private readonly FileService _fileService;
private readonly Dictionary<string, string> _styleDict = new Dictionary<string, string>()
{
{ "Trace", "default" },
{ "Debug", "success" },
{ "Information", "info" },
{ "Warning", "warning" },
{ "Error", "primary" },
{ "Critical", "danger" }
};
#region snippet1
public IndexModel(
IConfiguration config,
IConfigurationMonitor monitor,
FileService fileService)
{
_config = config;
_monitor = monitor;
_fileService = fileService;
}
#endregion
public string DefaultLogLevel { get; private set; }
public string SystemLogLevel { get; private set; }
public string MicrosoftLogLevel { get; private set; }
public HtmlString FileContents { get; private set; }
[TempData]
public string CurrentState { get; set; }
public async Task OnGet()
{
DefaultLogLevel = _config["Logging:LogLevel:Default"];
SystemLogLevel = _config["Logging:LogLevel:System"];
MicrosoftLogLevel = _config["Logging:LogLevel:Microsoft"];
ViewData["IncludeScopesStyle"] = string.Equals(_config["Logging:IncludeScopes"], "True", StringComparison.OrdinalIgnoreCase) ? "success" : "danger";
ViewData["DefaultLogLevelStyle"] = _styleDict[_config["Logging:LogLevel:Default"]];
ViewData["SystemLogLevelStyle"] = _styleDict[_config["Logging:LogLevel:System"]];
ViewData["MicrosoftLogLevelStyle"] = _styleDict[_config["Logging:LogLevel:Microsoft"]];
CurrentState = _monitor.CurrentState;
#region snippet3
var fileContent = await _fileService.GetFileContents("poem.txt");
#endregion
FileContents = new HtmlString(fileContent.Replace("\r\n", "<br>"));
}
#region snippet2
public IActionResult OnPostStartMonitoring()
{
_monitor.MonitoringEnabled = true;
_monitor.CurrentState = "Monitoring!";
return RedirectToPage();
}
public IActionResult OnPostStopMonitoring()
{
_monitor.MonitoringEnabled = false;
_monitor.CurrentState = "Not monitoring";
return RedirectToPage();
}
#endregion
}
}