使用Exceptionless记录日志

第一部分:搭建本地Exceptionless环境

 

提前先下载好对应的程序包

 

第一步,安装JDK并配置环境变量

第二步,解压elasticsearch,进入bin目录,运行elasticsearch.bat。

 

第三步,解压 Exceptionless,  运行Start.bat。

 

 在执行Start.bat的时候,如果出现以下错误,请参考PowerShell设置

 

如果没有报错,会出现这个界面。

等待安装完成,会自动打开http://localhost:50000/这个页面。

在低版本的安装过程中,需要修改各种配置文件,在最新版本已经不需要手动去修改了,完全是傻瓜式安装。

到此为止,安装流程已经全部完成了。

 

 

第二部分:代码调用

 在登录页面创建好账号并登录,新建一个项目。

 

点击“Add Project”后,会引导选择使用的框架,然后会给出对应框架的使用语句。

 

在VS中创建一个新的测试项目,我这边的代码和平台给的示例稍微有点不同,我把配置写在了json文件中。

 

Startup类里面加上这两行代码,把服务注册到系统中。

 

最后在控制器里面调用对应的方法。

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Threading.Tasks;
 5 using Exceptionless;
 6 using Exceptionless.Logging;
 7 using Microsoft.AspNetCore.Mvc;
 8 
 9 namespace ExceptionlessLogTest_V2.Controllers
10 {
11     [Route("api/[controller]")]
12     public class ValuesController : Controller
13     {
14         // GET api/values
15         [HttpGet]
16         public string Get()
17         {
18             ELogInfo("Get", $"logging-date:{DateTime.Now}");
19             try
20             {
21                 throw new Exception("Unable to create order from quote.");
22             }
23             catch (Exception ex)
24             {
25                 ELogError(ex, "err");
26             }
27 
28             return "执行完成";
29         }
30 
31 
32         public void ELogInfo(string source, string message, string tag = "")
33         {
34             if (string.IsNullOrEmpty(tag))
35             {
36                 ExceptionlessClient.Default.CreateLog(source, message, LogLevel.Info).Submit();
37             }
38             else
39             {
40                 ExceptionlessClient.Default.CreateLog(source, message, LogLevel.Info).AddTags(tag).Submit();
41             }
42         }
43 
44 
45         public void ELogError(Exception ex, string tag = "")
46         {
47             if (string.IsNullOrEmpty(tag))
48             {
49                 ExceptionlessClient.Default.SubmitException(ex);
50             }
51             else
52             {
53                 ExceptionlessClient.Default.CreateException(ex).SetProperty("ex", tag).Submit();
54             }
55         }
56 
57     }
58 }
View Code

 

更多的使用,请参考官方文档或者 savorboard的文章 

 

在调用了Get这个接口之后,对应的日志信息和异常信息已经记录到Exceptionless中了。最终效果如下:

  

 

参考链接:

http://www.cnblogs.com/liying0721/p/7027121.html#3738569

https://www.cnblogs.com/savorboard/p/exceptionless.html

转载于:https://www.cnblogs.com/jiao006/p/7652431.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值