You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/blazor/handle-errors.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ description: Discover how ASP.NET Core Blazor how Blazor manages unhandled excep
5
5
monikerRange: '>= aspnetcore-3.1'
6
6
ms.author: riande
7
7
ms.custom: mvc
8
-
ms.date: 03/29/2020
8
+
ms.date: 04/23/2020
9
9
no-loc: [Blazor, SignalR]
10
10
uid: blazor/handle-errors
11
11
---
@@ -106,6 +106,8 @@ During development, Blazor usually sends the full details of exceptions to the b
106
106
107
107
You must decide which incidents to log and the level of severity of logged incidents. Hostile users might be able to trigger errors deliberately. For example, don't log an incident from an error where an unknown `ProductId` is supplied in the URL of a component that displays product details. Not all errors should be treated as high-severity incidents for logging.
108
108
109
+
For more information, see <xref:fundamentals/logging/index#create-logs-in-blazor>.
110
+
109
111
## Places where errors may occur
110
112
111
113
Framework and app code may trigger unhandled exceptions in any of the following locations:
Copy file name to clipboardExpand all lines: aspnetcore/fundamentals/logging/index.md
+61-2Lines changed: 61 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ description: Learn how to use the logging framework provided by the Microsoft.Ex
5
5
monikerRange: '>= aspnetcore-2.1'
6
6
ms.author: riande
7
7
ms.custom: mvc
8
-
ms.date: 4/17/2020
8
+
ms.date: 4/23/2020
9
9
uid: fundamentals/logging/index
10
10
---
11
11
# Logging in .NET Core and ASP.NET Core
@@ -159,7 +159,9 @@ If you need to configure a service that depends on `ILogger<T>`, you can still d
159
159
160
160
The preceding highlighted code is a `Func` that runs the first time the DI container needs to construct an instance of `MyService`. You can access any of the registered services in this way.
161
161
162
-
### Create logs in Blazor WebAssembly
162
+
### Create logs in Blazor
163
+
164
+
#### Blazor WebAssembly
163
165
164
166
Configure logging in Blazor WebAssembly apps with the `WebAssemblyHostBuilder.Logging` property in `Program.Main`:
The `Logging` property is of type <xref:Microsoft.Extensions.Logging.ILoggingBuilder>, so all of the extension methods available on <xref:Microsoft.Extensions.Logging.ILoggingBuilder> are also available on `Logging`.
178
180
181
+
#### Log in Razor components
182
+
183
+
Loggers respect app startup configuration.
184
+
185
+
The `using` directive for <xref:Microsoft.Extensions.Logging> is required to support Intellisense completions for APIs, such as <xref:Microsoft.Extensions.Logging.LoggerExtensions.LogWarning%2A> and <xref:Microsoft.Extensions.Logging.LoggerExtensions.LogError%2A>.
186
+
187
+
The following example demonstrates logging with an <xref:Microsoft.Extensions.Logging.ILogger> in Razor components:
var logger = LoggerFactory.CreateLogger<Counter>();
231
+
logger.LogWarning("Someone has clicked me!");
232
+
233
+
currentCount++;
234
+
}
235
+
}
236
+
```
237
+
179
238
### No asynchronous logger methods
180
239
181
240
Logging should be so fast that it isn't worth the performance cost of asynchronous code. If your logging data store is slow, don't write to it directly. Consider writing the log messages to a fast store initially, then move them to the slow store later. For example, if you're logging to SQL Server, you don't want to do that directly in a `Log` method, since the `Log` methods are synchronous. Instead, synchronously add log messages to an in-memory queue and have a background worker pull the messages out of the queue to do the asynchronous work of pushing data to SQL Server. For more information, see [this](https://github.com/dotnet/AspNetCore.Docs/issues/11801) GitHub issue.
0 commit comments