Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze .net Core Integration Exceptionless distributed Log function and Global exception filtering

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

How to analyze. Net Core integration Exceptionless distributed logging features and global exception filtering, for this problem, this article details the corresponding analysis and solution, hoping to help more want to solve this problem of small partners to find a simpler and easier way.

Manual Send Error

After importing the namespace, you can simply submit an exception log using the following code:

try {

throw new ApplicationException(Guid.NewGuid().ToString());} catch (Exception ex) { ex.ToExceptionless().Submit();} Send additional information

Of course, you can also add additional tag information to the event sent, such as coordinates, tags, and other user-related information.

Uniform modification of unhandled exception reports

You can add custom information to the global ignore exception information set via SubmittingEvent events, and so on.

Use with NLog or Log4Net

Sometimes, applications need to log information in great detail, such as during development. At this time, you can use exceptionless jointly with log4 net or nlog. For details, please see this official [example][https://github.com/exceptionless/Exceptionless.Net/tree/master/samples/Exceptionless.SampleConsole].

If your program generates a large number of logs in a short period of time, such as thousands of logs per minute. At this point you need to use an in-memory store for events, so the client doesn't serialize events to disk, so it's much faster. This allows you to use Log4 net or Nlog to store some events to disk and Exceptionless events to memory.

Exceptionless logging encapsulation

1. Start by simply encapsulating an ILoggerHelper interface

Now that there's an interface, of course you have to implement it.

Of course it's done. Don't forget dependency injection.

//inject ExceptionlessLogger service services.AddSingleton();

It's time to write a global exception filter.

The global filter has been written, how to make it effective? Objectively, don't worry, serve the main dish.

//add validation services.AddMvc(options=> { options.Filters.Add(); }).AddFluentValidation();

Haha, nothing to say, the code has been written, the rest is on the code test results. I am here just a simple api test, universal ValuesController debut:

Here is a direct exception thrown, do not trycatch, this time the exception will be caught by the global filter, and then put into the Exceptionless Log inside, do not ask me why it is in the log, because I have written in the global filter code, do not understand go back to see the code, and then look at the implementation method of the interface call. Below are the results:

Go in and see the details:

Then test the exception handling caught using try catch, and the exception information will be submitted to Exception. Go ahead and code.

Go to Exceptionless to see the exceptions that don't live. Typing is very tiring. Go directly to the picture

Click to see the details, there are three tabs, the following paste a picture:

About how to analyze. Net Core integration Exceptionless distributed log function and global exception filtering questions to share here, I hope the above content can be of some help to everyone, if you still have a lot of doubts not solved, you can pay attention to the industry information channel to learn more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report