preface

For the log recording part of the project currently used by the company, Log4net has always been used and stored in the background file. It is very inconvenient for abnormal errors or the need to view some details of errors. It is necessary to open the log file on the server to retrieve errors, which reduces the speed of solving problems. So optimization for the logging area is on the agenda. The Exceptionalism log framework was used to process and collect system logs. In the actual operation, I also encountered a lot of pits, now the Exceptionalism distributed log framework on Windows localization deployment to make a record.

1. Install ExceptionProofing

GitHub has a detailed introduction to the Exceptionalism, and our preparations are mainly as follows:

. Net4.7

IIS 7.5 +

PowerShell 3+

Java JDK 1.8 +

Because both the local environment and the generated environment use Windows, the exception deployment focus on how to deploy on Windows, there are many related documents on the Internet is directly deployed on Linux, but this is not the focus of this article.

About the Java environment configuration can refer to the following article Java installation and environment configuration article written in detail, follow the configuration down is not too big a problem.

Then, we will download ExceptionLess4.1.2861, the latest version of GitHub is ExceptionLess4.1.2861

After downloading, unzip the file and you can see the following files

ElasticSearch and website.ps1 will install and run ElasticSearch and Kibana.

In this step in the process of installation, the most problems, but also the most difficult to solve, is really toss and toss for a long time.

Q: Run start. bat. If the request is aborted, the SSL/TLS security channel cannot be established.

A: Add the following command to the end of the elasticSearch. ps1 file:

2. Then, Start start. bat again, you can see that the web stream was downloaded and written normally. This process seems to be very long, I remember that I left my computer on at night, so I kept letting it download. This seems to have something to do with its own network.

Waiting for the download, just in the file will be more than a few folders.

The exceptiondefault port number is 50000. If the default port number is 50000, enter localhost:50000 in the browser to display the login page.

An error occurred trying to red the response from the specified node.

The ElasticSearch service needs to be enabled for each access. The ElasticSearch service is registered with Windows and automatically starts every startup. This saves the trouble of executing start. bat and opening four DOS Windows at a time.

For ElasticSearch, run the CMD command in the bin directory on node1 to open the command window

Run elasticSearch -sevice. Bat install to install the elasticSearch service. Run the elsticsearch-service.bat start command to start the service

Subsequently, we directly set the startup mode of the service to automatic in the service to complete the registration.

We then deployed the Exceptionalism to IIS, and created a new website under the directory wwwroot. The default port number is 50000. If you need to change the port number,

Remember to modify BASE_URL in app.config.xxxx.js;

Change the port number in web.config.

The port numbers of the last two lines of the start-website.ps1 file also need to be changed.

After all this, we can finally access the local Exceptionalism.

The exception Set in the.NET Core project

Because the project environment we are using is.net Core, we created an organization with any name in the ExceptionAlism model, and then created a new project with the exceptionalism model.AspNetCore was selected as the project framework

The method to use is simple. Directly use app. Useexceptionalism (” XXXXXAPI key “) in the startup.cs project.

Here, I put some of the Exception Settings in appSettings. json so we can write that in startup.cs

  var isEnableLogger = Convert.ToBoolean(_appConfiguration["Exceptionless:Enabled"]????"false");
        if (isEnableLogger)
        {
            // Encapsulate the Exceptionless distributed log component
            ExceptionlessClient.Default.Configuration.ApiKey = _appConfiguration["Exceptionless:ApiKey"];
            ExceptionlessClient.Default.Configuration.ServerUrl = _appConfiguration["Exceptionless:ServerUrl"];
            app.UseExceptionless();
        }
Copy the code

Then we can try to manually throw an exception to see if the Exception is caught.

   public ActionResult<IEnumerable<string>> Get()
        {
            throw new Exception($" look here abnormal! Time:{DateTime.Now}");
            return new string[] { "value1"."value2" };
        }
Copy the code

We can see that our exception succeeds in trapping the exception by default, or we can manually submit an exception message to the Exception model.

   // GET api/values/5
        [HttpGet("{id}")]
        public ActionResult<string> Get(int id)
        {
            try
            {

                throw new Exception("Abnormal");
                return "value";
            }
            catch (Exception ex)
            {
                ex.ToExceptionless().Submit();
            }
            return "value";
        }
Copy the code

Of course, these examples are very simple, in fact, the most important is the Exceptionalism installation process, is really encountered a lot of let head big problems, but fortunately, these problems are finally solved.

Currently, the Exceptionalism log framework has only been installed and deployed in a local test environment. The time zone problem mentioned by the Exception log framework has not been deployed in the build environment. This problem has not been encountered yet.

Conclusion

References:

This article in the process of editing reference to the following part of the content and information, thank you.

We wish, Exceptionalism Setup and Simple Operation

Markjiang7m2, Exceptionproofing.net Core Open Source Logging Framework

Markjiang7m2, ExceptionAlism (2) – Advanced Local Deployment

Java Environment Variable Configuration Java Environment Variable Configuration

Thanks again to the above authors.

For the use of exceptionalism, I also just started the entry, exceptionalism some other powerful features are waiting for us to further explore and in-depth study. Hope this article gives other small partners some help, welcome everybody to discuss the exchange together, I am the program ape beta.