设为首页 加入收藏

TOP

开源日志框架Exceptionless使用教程(一)
2019-09-19 11:10:47 】 浏览:74
Tags:开源 日志 框架 Exceptionless 使用 教程

Exceptionless是一款日志记录框架,它开源、免费、提供管理界面、易于安装和使用。ExceptionLess底层采用ElasticSearch作为日志存储,提供了快速、丰富的查询API,方便我们进行系统集成。本文将介绍ExceptionLess的常见用法。

安装ExceptionLess

在ExceptionLess官网提供了基于Docker的私有化部署方式,我们可以按照官网的方式进行测试环境的安装。

  1. 在官网github中下载最新的release包,地址:https://github.com/exceptionless/Exceptionless/releases
  2. 解压缩,然后进入解压缩的目录,执行 docker-compose up -d命令在后台启动多个容器,当执行完成后,Exceptionless已经在本地运行起来了。我们可以在Kitematic中查看运行中的容器
  3. 按照官网的说明,5000端口是登陆页面,但实际情况是5000是API,5100才是登陆页面,因此我们打开http://localhost:5100进入登陆页面。注意:此处可能跟版本有关,在使用时查看docker的端口映射。

通过以上步骤,就在本地搭建好了测试环境。我们可以看到启动的总共启动了6个容器,分别是redis、elasticsearch、kibana、Exceptionless Job、Exceptionless Api、Excetpionless UI。

快速上手

搭建好测试环境后,首先访问Exceptionless UI来创建用户、组织和项目。然后,当项目创建完成之后,Exceptionless 会跳转到客户端配置页面,来指引我们如何使用Exceptionless客户端。我们可以选择自己需要用到的客户端,通过页面的指引完成客户端配置。

引导页面如下:

image

按照这种方式我们可以完成.Net平台项目、JS项目的配置。

客户端API:https://github.com/exceptionless/Exceptionless.Net/wiki

配置好以后,我们就可以记录日志了,例如(代码来源于官网):

// Import the exceptionless namespace.
using Exceptionless;

// Submit logs
ExceptionlessClient.Default.SubmitLog("Logging made easy");

// You can also specify the log source and log level.
// We recommend specifying one of the following log levels: Trace, Debug, Info, Warn, Error
ExceptionlessClient.Default.SubmitLog(typeof(Program).FullName, "This is so easy", "Info");
ExceptionlessClient.Default.CreateLog(typeof(Program).FullName, "This is so easy", "Info").AddTags("Exceptionless").Submit();

// Submit feature usages
ExceptionlessClient.Default.SubmitFeatureUsage("MyFeature");
ExceptionlessClient.Default.CreateFeatureUsage("MyFeature").AddTags("Exceptionless").Submit();

// Submit a 404
ExceptionlessClient.Default.SubmitNotFound("/somepage");
ExceptionlessClient.Default.CreateNotFound("/somepage").AddTags("Exceptionless").Submit();

// Submit a custom event type
ExceptionlessClient.Default.SubmitEvent(new Event { Message = "Low Fuel", Type = "racecar", Source = "Fuel System" });

功能介绍

Exceptionless中的事件有以下几种类型:

  • 日志消息:记录的日志,可以是任何文本内容
  • 特性使用:功能使用量的记录,例如接口调用情况等
  • 异常情况:记录异常的信息
  • 失效链接:当被访问的页面不存在时进行记录

除了记录内容外,Exceptionless还支持对事件添加标签、附加数据、用户描述等操作,例如(代码来源于官网):

try {
    throw new ApplicationException("Unable to create order from quote.");
} catch (Exception ex) {
    ex.ToExceptionless()
        // Set the reference id of the event so we can search for it later (reference:id).
        // This will automatically be populated if you call ExceptionlessClient.Default.Configuration.UseReferenceIds();
        .SetReferenceId(Guid.NewGuid().ToString("N"))
        // Add the order object but exclude the credit number property.
        .AddObject(order, "Order", excludedPropertyNames: new [] { "CreditCardNumber" }, maxDepth: 2)
        // Set the quote number.
        .SetProperty("Quote", 123)
        // Add an order tag.
        .AddTags("Order")
        // Mark critical.
        .MarkAsCritical()
        // Set the coordinates of the end user.
        .SetGeo(43.595089, -88.444602)
        // Set the user id that is in our system and provide a friendly name.
        .SetUserIdentity(user.Id, user.FullName)
        // Set the users description of the error.
        .SetUserDe
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇webform的原生操作图片预览和上传 下一篇前后台分离的 NET Core 通用权限..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目