Skip to content

Commit 997f70f

Browse files
authored
Fix broken links and some code highlights in Logging (#18227)
1 parent 0b6d5ec commit 997f70f

File tree

2 files changed

+34
-35
lines changed

2 files changed

+34
-35
lines changed

aspnetcore/fundamentals/logging/index.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: rick-anderson
44
description: Learn how to use the logging framework provided by the Microsoft.Extensions.Logging NuGet package.
55
ms.author: riande
66
ms.custom: mvc
7-
ms.date: 5/8/2020
7+
ms.date: 5/9/2020
88
no-loc: [Blazor, "Identity", "Let's Encrypt", Razor, SignalR]
99
uid: fundamentals/logging/index
1010
---
@@ -328,7 +328,7 @@ With the preceding setup, navigating to the privacy or home page produces many `
328328

329329
The following code sets the default log level when the default log level is not set in configuration:
330330

331-
[!code-csharp[](index/samples/3.x/MyMain/Program.cs?name=snippet_MinLevel&highlight=9)]
331+
[!code-csharp[](index/samples/3.x/MyMain/Program.cs?name=snippet_MinLevel&highlight=10)]
332332

333333
<!-- review required: I say this a couple times -->
334334
Generally, log levels should be specified in configuration and not code.
@@ -405,8 +405,7 @@ ASP.NET Core includes the following logging providers:
405405
* [Debug](#debug-provider)
406406
* [EventSource](#event-source-provider)
407407
* [EventLog](#welog)
408-
* [AzureAppServicesFile](#azure-app-service-provider)
409-
* [AzureAppServicesBlob](#azure-app-service-provider)
408+
* [AzureAppServicesFile and AzureAppServicesBlob](#azure-app-service)
410409
* [ApplicationInsights](#azure-application-insights)
411410

412411
For information on `stdout` and debug logging with the ASP.NET Core Module, see <xref:test/troubleshoot-azure-iis> and <xref:host-and-deploy/aspnet-core-module#log-creation-and-redirection>.
@@ -640,19 +639,19 @@ Logging code for apps without Generic Host differs in the way [providers are add
640639

641640
In a non-host console app, call the provider's `Add{provider name}` extension method while creating a `LoggerFactory`:
642641

643-
[!code-csharp[](index/samples/3.x/LoggingConsoleApp/Program.cs?name=snippet_LoggerFactory&highlight=1,7)]
642+
[!code-csharp[](index/samples/3.x/LoggingConsoleApp/Program.cs?name=snippet_LoggerFactory&highlight=11-12)]
644643

645644
### Create logs
646645

647646
To create logs, use an <xref:Microsoft.Extensions.Logging.ILogger%601> object. Use the `LoggerFactory` to create an `ILogger`.
648647

649648
The following example creates a logger with `LoggingConsoleApp.Program` as the category.
650649

651-
[!code-csharp[](index/samples/3.x/LoggingConsoleApp/Program.cs?name=snippet_LoggerFactory&highlight=10)]
650+
[!code-csharp[](index/samples/3.x/LoggingConsoleApp/Program.cs?name=snippet_LoggerFactory&highlight=14)]
652651

653652
In the following ASP.NET CORE examples, the logger is used to create logs with `Information` as the level. The Log *level* indicates the severity of the logged event.
654653

655-
[!code-csharp[](index/samples/3.x/LoggingConsoleApp/Program.cs?name=snippet_LoggerFactory&highlight=11)]
654+
[!code-csharp[](index/samples/3.x/LoggingConsoleApp/Program.cs?name=snippet_LoggerFactory&highlight=15)]
656655

657656
[Levels](#log-level) and [categories](#log-category) are explained in more detail in this document.
658657

aspnetcore/fundamentals/logging/index/samples/3.x/MyMain/Program.cs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using Microsoft.Extensions.Logging.EventLog;
1010
using MyMain;
1111

12-
1312
#if FilterCode
1413
#region snippet_FilterInCode
1514
public class Program
@@ -18,10 +17,11 @@ public static void Main(string[] args)
1817
{
1918
CreateHostBuilder(args).Build().Run();
2019
}
20+
2121
public static IHostBuilder CreateHostBuilder(string[] args) =>
2222
Host.CreateDefaultBuilder(args)
23-
.ConfigureLogging(log =>
24-
log.AddFilter("System", LogLevel.Debug)
23+
.ConfigureLogging(logging =>
24+
logging.AddFilter("System", LogLevel.Debug)
2525
.AddFilter<DebugLoggerProvider>("Microsoft", LogLevel.Information)
2626
.AddFilter<ConsoleLoggerProvider>("Microsoft", LogLevel.Trace))
2727
.ConfigureWebHostDefaults(webBuilder =>
@@ -39,31 +39,29 @@ public static void Main(string[] args)
3939
{
4040
CreateHostBuilder(args).Build().Run();
4141
}
42+
4243
public static IHostBuilder CreateHostBuilder(string[] args) =>
4344
Host.CreateDefaultBuilder(args)
44-
.ConfigureLogging(logBuilder =>
45+
.ConfigureLogging(logging =>
4546
{
46-
logBuilder.AddFilter((provider, category, logLevel) =>
47+
logging.AddFilter((provider, category, logLevel) =>
4748
{
4849
if (provider.Contains("ConsoleLoggerProvider")
4950
&& category.Contains("Controller")
50-
&& logLevel >= LogLevel.Information
51-
)
51+
&& logLevel >= LogLevel.Information)
5252
{
5353
return true;
5454
}
5555
else if (provider.Contains("ConsoleLoggerProvider")
5656
&& category.Contains("Microsoft")
57-
&& logLevel >= LogLevel.Information
58-
)
57+
&& logLevel >= LogLevel.Information)
5958
{
6059
return true;
6160
}
6261
else
6362
{
6463
return false;
6564
}
66-
6765
});
6866
})
6967
.ConfigureWebHostDefaults(webBuilder =>
@@ -81,6 +79,7 @@ public static void Main(string[] args)
8179
{
8280
CreateHostBuilder(args).Build().Run();
8381
}
82+
8483
public static IHostBuilder CreateHostBuilder(string[] args) =>
8584
Host.CreateDefaultBuilder(args)
8685
.ConfigureLogging(logging => logging.SetMinimumLevel(LogLevel.Warning))
@@ -99,6 +98,7 @@ public static void Main(string[] args)
9998
{
10099
CreateHostBuilder(args).Build().Run();
101100
}
101+
102102
public static IHostBuilder CreateHostBuilder(string[] args) =>
103103
Host.CreateDefaultBuilder(args)
104104
.ConfigureLogging((hostingContext, logging) =>
@@ -127,18 +127,18 @@ public static void Main(string[] args)
127127

128128
public static IHostBuilder CreateHostBuilder(string[] args) =>
129129
Host.CreateDefaultBuilder(args)
130-
.ConfigureLogging(logging => logging.AddAzureWebAppDiagnostics())
131-
.ConfigureServices(serviceCollection => serviceCollection
132-
.Configure<AzureFileLoggerOptions>(options =>
133-
{
134-
options.FileName = "azure-diagnostics-";
135-
options.FileSizeLimit = 50 * 1024;
136-
options.RetainedFileCountLimit = 5;
137-
}).Configure<AzureBlobLoggerOptions>(options =>
138-
{
139-
options.BlobName = "log.txt";
140-
})
141-
)
130+
.ConfigureLogging(logging => logging.AddAzureWebAppDiagnostics())
131+
.ConfigureServices(serviceCollection => serviceCollection
132+
.Configure<AzureFileLoggerOptions>(options =>
133+
{
134+
options.FileName = "azure-diagnostics-";
135+
options.FileSizeLimit = 50 * 1024;
136+
options.RetainedFileCountLimit = 5;
137+
})
138+
.Configure<AzureBlobLoggerOptions>(options =>
139+
{
140+
options.BlobName = "log.txt";
141+
}))
142142
.ConfigureWebHostDefaults(webBuilder =>
143143
{
144144
webBuilder.UseStartup<Startup>();
@@ -158,13 +158,13 @@ public static void Main(string[] args)
158158

159159
public static IHostBuilder CreateHostBuilder(string[] args) =>
160160
Host.CreateDefaultBuilder(args)
161-
.ConfigureLogging(logging =>
162-
{
163-
logging.AddEventLog(eventLogSettings =>
161+
.ConfigureLogging(logging =>
164162
{
165-
eventLogSettings.SourceName = "MyLogs";
166-
});
167-
})
163+
logging.AddEventLog(eventLogSettings =>
164+
{
165+
eventLogSettings.SourceName = "MyLogs";
166+
});
167+
})
168168
.ConfigureWebHostDefaults(webBuilder =>
169169
{
170170
webBuilder.UseStartup<Startup>();

0 commit comments

Comments
 (0)