Skip to content

Commit f4e3e2c

Browse files
CSAT on logging (#17820)
* CSAT on logging * work * work * work * work * work * work * work * work * work * work * work * work * work * work * work * work * work * work * work * work * work * work * more work * more work * more work * more work * more work * more work * add where to open logging bugs * add where to open logging bugs * Apply suggestions from code review Co-authored-by: Kirk Larkin <6025110+serpent5@users.noreply.github.com> * add where to open logging bugs Co-authored-by: Kirk Larkin <6025110+serpent5@users.noreply.github.com>
1 parent 54bcf21 commit f4e3e2c

File tree

87 files changed

+80652
-573
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+80652
-573
lines changed

aspnetcore/fundamentals/environments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,4 +728,4 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args)
728728
* <xref:fundamentals/startup>
729729
* <xref:fundamentals/configuration/index>
730730

731-
::: moniker-end
731+
::: moniker-end

aspnetcore/fundamentals/logging/index.md

Lines changed: 508 additions & 525 deletions
Large diffs are not rendered by default.
Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
using Microsoft.Extensions.Logging;
22

3-
namespace LoggingConsoleApp
3+
#region snippet_LoggerFactory
4+
class Program
45
{
5-
class Program
6+
static void Main(string[] args)
67
{
7-
static void Main(string[] args)
8+
var loggerFactory = LoggerFactory.Create(builder =>
89
{
9-
#region snippet_LoggerFactory
10-
var loggerFactory = LoggerFactory.Create(builder =>
11-
{
12-
builder
13-
.AddFilter("Microsoft", LogLevel.Warning)
14-
.AddFilter("System", LogLevel.Warning)
15-
.AddFilter("LoggingConsoleApp.Program", LogLevel.Debug)
16-
.AddConsole()
17-
.AddEventLog();
18-
});
19-
ILogger logger = loggerFactory.CreateLogger<Program>();
20-
logger.LogInformation("Example log message");
21-
#endregion
22-
}
10+
builder
11+
.AddFilter("Microsoft", LogLevel.Warning)
12+
.AddFilter("System", LogLevel.Warning)
13+
.AddFilter("LoggingConsoleApp.Program", LogLevel.Debug)
14+
.AddConsole()
15+
.AddEventLog();
16+
});
17+
ILogger logger = loggerFactory.CreateLogger<Program>();
18+
logger.LogInformation("Example log message");
2319
}
24-
}
20+
}
21+
#endregion
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "None",
5+
"Microsoft": "None",
6+
"Microsoft.Hosting.Lifetime": "None"
7+
}
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "None",
5+
"Microsoft": "None",
6+
"Microsoft.Hosting.Lifetime": "None"
7+
}
8+
}
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
},
9+
"AllowedHosts": "*"
10+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.Docs.Samples;
8+
using Microsoft.Extensions.Logging;
9+
using MyMain.Models;
10+
11+
namespace MyMain.Controllers
12+
{
13+
public class HomeController : Controller
14+
{
15+
private readonly ILogger<HomeController> _logger;
16+
17+
18+
public HomeController(ILogger<HomeController> logger)
19+
{
20+
_logger = logger;
21+
}
22+
23+
public IActionResult Index()
24+
{
25+
var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
26+
ViewData["Message"] = $"ASPNETCORE_ENVIRONMENT = {env}";
27+
return View();
28+
}
29+
30+
public IActionResult Privacy()
31+
{
32+
var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
33+
ViewData["Message"] = $"ASPNETCORE_ENVIRONMENT = {env}";
34+
var routeInfo = ControllerContext.ToCtxString();
35+
_logger.LogWarning(2000,"Test {x}", routeInfo);
36+
_logger.LogInformation(1100, "Test {x}", routeInfo);
37+
38+
return View();
39+
}
40+
41+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
42+
public IActionResult Error()
43+
{
44+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
45+
}
46+
}
47+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace MyMain.Models
4+
{
5+
public class ErrorViewModel
6+
{
7+
public string RequestId { get; set; }
8+
9+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
10+
}
11+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ProjectExtensions><VisualStudio><UserProperties properties_4launchsettings_1json__JsonSchema="http://json.schemastore.org/npmpackagejsonlintrc" /></VisualStudio></ProjectExtensions>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="3.1.3" />
11+
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="3.1.3" />
12+
<PackageReference Include="Rick.Docs.Samples.RouteInfo" Version="1.0.0.4" />
13+
</ItemGroup>
14+
15+
16+
17+
</Project>

0 commit comments

Comments
 (0)