米易网,素颜格格大明英烈传,替米沙坦片价格
exceptionless是一款日志记录框架,它开源、免费、提供管理界面、易于安装和使用。exceptionless底层采用elasticsearch作为日志存储,提供了快速、丰富的查询api,方便我们进行系统集成。本文将介绍exceptionless的常见用法。
在exceptionless官网提供了基于docker的私有化部署方式,我们可以按照官网的方式进行测试环境的安装。
docker-compose up -d
命令在后台启动多个容器,当执行完成后,exceptionless已经在本地运行起来了。我们可以在kitematic中查看运行中的容器通过以上步骤,就在本地搭建好了测试环境。我们可以看到启动的总共启动了6个容器,分别是redis、elasticsearch、kibana、exceptionless job、exceptionless api、excetpionless ui。
搭建好测试环境后,首先访问exceptionless ui来创建用户、组织和项目。然后,当项目创建完成之后,exceptionless 会跳转到客户端配置页面,来指引我们如何使用exceptionless客户端。我们可以选择自己需要用到的客户端,通过页面的指引完成客户端配置。
引导页面如下:
按照这种方式我们可以完成.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. .setuserdescription(user.emailaddress, "i tried creating an order from my saved quote.") // submit the event. .submit(); }
官方支持nlog、log4net集成的支持,只需要添加相应的日志组件的配置文件即可。以log4net为例:
首先添加程序集的支持:
install-package exceptionless.log4net
然后在log4net的配置文件中进行配置(代码来源于官网):
<log4net> <appender name="exceptionless" type="exceptionless.log4net.exceptionlessappender,exceptionless.log4net"> <layout type="log4net.layout.patternlayout"> <conversionpattern value="%-4timestamp [%thread] %-5level %logger %ndc - %message%newline"/> </layout> </appender> <root> <level value="debug"/> <appender-ref ref="exceptionless"/> </root> </log4net>
除了丰富的客户端功能外,exceptionless还提供了大量api的支持,这些api可以在5000端口访问到。地址为::
通过这些接口,我们可以实现更多自定义的操作,例如用户授权、项目管理、日志查询等操作。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论