Skip to content

Commit 29d5ef2

Browse files
committed
Logging article overhaul
1 parent 46fd037 commit 29d5ef2

File tree

8 files changed

+939
-1366
lines changed

8 files changed

+939
-1366
lines changed

aspnetcore/blazor/fundamentals/logging.md

Lines changed: 5 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: ASP.NET Core Blazor logging
33
author: guardrex
4-
description: Learn about Blazor app logging, including configuration and how to write log messages from Razor components.
4+
description: Learn about Blazor app logging, particularly in client-side logging scenarios.
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: wpickett
77
ms.custom: mvc
8-
ms.date: 11/12/2024
8+
ms.date: 09/29/2025
99
uid: blazor/fundamentals/logging
1010
---
1111
# ASP.NET Core Blazor logging
@@ -17,7 +17,9 @@ uid: blazor/fundamentals/logging
1717
at the ends of lines to generate a bare return in block quote output.
1818
-->
1919

20-
This article explains Blazor app logging, including configuration and how to write log messages from Razor components.
20+
This article provides information on logging in Blazor apps, particularly in client-side logging scenarios.
21+
22+
For general ASP.NET Core logging guidance, including how to log from Razor components, see <xref:fundamentals/logging/index>.
2123

2224
## Configuration
2325

@@ -38,101 +40,6 @@ When the app is configured in the project file to use implicit namespaces (`<Imp
3840

3941
Log levels conform to ASP.NET Core app log levels, which are listed in the API documentation at <xref:Microsoft.Extensions.Logging.LogLevel>.
4042

41-
## Razor component logging
42-
43-
:::moniker range="< aspnetcore-6.0"
44-
45-
The `using` directive for <xref:Microsoft.Extensions.Logging> is required to support [IntelliSense](/visualstudio/ide/using-intellisense) completions for APIs, such as <xref:Microsoft.Extensions.Logging.LoggerExtensions.LogWarning%2A> and <xref:Microsoft.Extensions.Logging.LoggerExtensions.LogError%2A>.
46-
47-
:::moniker-end
48-
49-
The following example:
50-
51-
* [Injects](xref:blazor/fundamentals/dependency-injection) an <xref:Microsoft.Extensions.Logging.ILogger> (`ILogger<Counter1>`) object to create a logger. The log's *category* is the fully qualified name of the component's type, `Counter`.
52-
* Calls <xref:Microsoft.Extensions.Logging.LoggerExtensions.LogWarning%2A> to log at the <xref:Microsoft.Extensions.Logging.LogLevel.Warning> level.
53-
54-
`Counter1.razor`:
55-
56-
:::moniker range=">= aspnetcore-9.0"
57-
58-
:::code language="razor" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/Components/Pages/Counter1.razor":::
59-
60-
:::moniker-end
61-
62-
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
63-
64-
:::code language="razor" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Components/Pages/Counter1.razor":::
65-
66-
:::moniker-end
67-
68-
:::moniker range=">= aspnetcore-7.0 < aspnetcore-8.0"
69-
70-
:::code language="razor" source="~/../blazor-samples/7.0/BlazorSample_WebAssembly/Pages/logging/Counter1.razor":::
71-
72-
:::moniker-end
73-
74-
:::moniker range=">= aspnetcore-6.0 < aspnetcore-7.0"
75-
76-
:::code language="razor" source="~/../blazor-samples/6.0/BlazorSample_WebAssembly/Pages/logging/Counter1.razor":::
77-
78-
:::moniker-end
79-
80-
:::moniker range=">= aspnetcore-5.0 < aspnetcore-6.0"
81-
82-
:::code language="razor" source="~/../blazor-samples/5.0/BlazorSample_WebAssembly/Pages/logging/Counter1.razor":::
83-
84-
:::moniker-end
85-
86-
:::moniker range="< aspnetcore-5.0"
87-
88-
:::code language="razor" source="~/../blazor-samples/3.1/BlazorSample_WebAssembly/Pages/logging/Counter1.razor":::
89-
90-
:::moniker-end
91-
92-
The following example demonstrates logging with an <xref:Microsoft.Extensions.Logging.ILoggerFactory> in components.
93-
94-
`Counter2.razor`:
95-
96-
:::moniker range=">= aspnetcore-9.0"
97-
98-
:::code language="razor" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/Components/Pages/Counter2.razor":::
99-
100-
:::moniker-end
101-
102-
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
103-
104-
:::code language="razor" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Components/Pages/Counter2.razor":::
105-
106-
:::moniker-end
107-
108-
:::moniker range=">= aspnetcore-7.0 < aspnetcore-8.0"
109-
110-
:::code language="razor" source="~/../blazor-samples/7.0/BlazorSample_WebAssembly/Pages/logging/Counter2.razor":::
111-
112-
:::moniker-end
113-
114-
:::moniker range=">= aspnetcore-6.0 < aspnetcore-7.0"
115-
116-
:::code language="razor" source="~/../blazor-samples/6.0/BlazorSample_WebAssembly/Pages/logging/Counter2.razor":::
117-
118-
:::moniker-end
119-
120-
:::moniker range=">= aspnetcore-5.0 < aspnetcore-6.0"
121-
122-
:::code language="razor" source="~/../blazor-samples/5.0/BlazorSample_WebAssembly/Pages/logging/Counter2.razor":::
123-
124-
:::moniker-end
125-
126-
:::moniker range="< aspnetcore-5.0"
127-
128-
:::code language="razor" source="~/../blazor-samples/3.1/BlazorSample_WebAssembly/Pages/logging/Counter2.razor":::
129-
130-
:::moniker-end
131-
132-
## Server-side logging
133-
134-
For general ASP.NET Core logging guidance, see <xref:fundamentals/logging/index>.
135-
13643
## Client-side logging
13744

13845
Not every feature of [ASP.NET Core logging](xref:fundamentals/logging/index) is supported client-side. For example, client-side components don't have access to the client's file system or network, so writing logs to the client's physical or network storage isn't possible. When using a third-party logging service designed to work with single-page apps (SPAs), follow the service's security guidance. Keep in mind that every piece of data, including keys or secrets stored client-side are ***insecure*** and can be easily discovered by malicious users.

0 commit comments

Comments
 (0)