-
Notifications
You must be signed in to change notification settings - Fork 751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding ExceptionSummarization readme #4610
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 77 additions & 1 deletion
78
src/Libraries/Microsoft.Extensions.Diagnostics.ExceptionSummarization/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,77 @@ | ||
README | ||
# Microsoft.Extensions.Diagnostics.ExceptionSummarization | ||
|
||
This provides the ability to extract essential information from well-known exception types and return a single string that can be used to create low-cardinality diagnostic messages for use in telemetry. | ||
|
||
## Install the package | ||
|
||
From the command-line: | ||
|
||
```dotnetcli | ||
dotnet add package Microsoft.Extensions.Diagnostics.ExceptionSummarization | ||
``` | ||
|
||
Or directly in the C# project file: | ||
|
||
```xml | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Diagnostics.ExceptionSummarization" Version="[CURRENTVERSION]" /> | ||
</ItemGroup> | ||
``` | ||
|
||
## Usage Example | ||
|
||
### Registering Services | ||
|
||
The services can be registered using the following methods: | ||
|
||
```csharp | ||
public static IServiceCollection AddExceptionSummarizer(this IServiceCollection services); | ||
public static IServiceCollection AddExceptionSummarizer(this IServiceCollection services, Action<IExceptionSummarizationBuilder> configure); | ||
``` | ||
|
||
For example: | ||
|
||
```csharp | ||
services.AddExceptionSummarizer(); | ||
``` | ||
|
||
The package comes with a predefined `IExceptionSummaryProvider` implementation which will work with common | ||
sebastienros marked this conversation as resolved.
Show resolved
Hide resolved
|
||
exceptions that might be sent during a web request. Here is how to register it: | ||
|
||
```csharp | ||
using Microsoft.Extensions.Diagnostics.ExceptionSummarization; | ||
|
||
services.AddExceptionSummarizer(b => b.AddHttpProvider()); | ||
``` | ||
|
||
### Consuming Services | ||
|
||
Once registered, the `IExceptionSummarizer` class can be resolved. For example: | ||
|
||
```csharp | ||
using Microsoft.Extensions.Diagnostics.ExceptionSummarization; | ||
|
||
var summarizer = services.BuildServiceProvider().GetRequiredService<IExceptionSummarizer>(); | ||
|
||
try | ||
{ | ||
throw new SocketException((int)SocketError.NetworkDown); | ||
} | ||
catch (Exception e) | ||
{ | ||
ExceptionSummary summary = summarizer.Summarize(e); | ||
|
||
Console.WriteLine(summary.Description); // writes NetworkDown | ||
} | ||
``` | ||
|
||
The `ExceptionSummary.Description` property never includes sensitive information and can be safely used. | ||
As opposed to `ExceptionSummary.AdditionalDetails` which can contain sensitive information that should not be stored and can only be used for debugging purpose. | ||
|
||
## Custom exception summarization | ||
|
||
Custom implementations of the `IExceptionSummaryProvider` interface can be used to provide a summary for any type of exception. | ||
|
||
## Feedback & Contributing | ||
|
||
We welcome feedback and contributions in [our GitHub repo](https://github.com/dotnet/extensions). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be VB or F#
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have this pre-defined for all readmes. Let's do a separate global change once we agree on this, but keep it consistent for now a least.