feat(Rollbar): 增加异常通知功能

This commit is contained in:
Argo Zhang 2019-05-28 10:46:11 +08:00
parent 8ce886af81
commit 22b863ff24
3 changed files with 12 additions and 0 deletions

View File

@ -20,6 +20,7 @@
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.7.9" /> <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.7.9" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" PrivateAssets="All" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" PrivateAssets="All" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="Rollbar.NetCore.AspNet" Version="3.1.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -13,8 +13,10 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Versioning; using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Serialization;
using Rollbar.NetCore.AspNet;
using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.Swagger;
using System; using System;
using System.IO; using System.IO;
@ -70,6 +72,10 @@ namespace Bootstrap.Admin
services.AddSignalR().AddJsonProtocalDefault(); services.AddSignalR().AddJsonProtocalDefault();
services.AddSignalRExceptionFilterHandler<SignalRHub>(async (client, ex) => await SignalRManager.Send(client, ex)); services.AddSignalRExceptionFilterHandler<SignalRHub>(async (client, ex) => await SignalRManager.Send(client, ex));
services.AddResponseCompression(); services.AddResponseCompression();
services.AddRollbarLogger(loggerOptions =>
{
loggerOptions.Filter = (loggerName, loglevel) => loglevel >= LogLevel.Trace;
});
services.AddMvc(options => services.AddMvc(options =>
{ {
options.Filters.Add<BootstrapAdminAuthorizeFilter>(); options.Filters.Add<BootstrapAdminAuthorizeFilter>();
@ -137,6 +143,7 @@ namespace Bootstrap.Admin
app.UseOnlineUsers(callback: TraceHelper.Save); app.UseOnlineUsers(callback: TraceHelper.Save);
app.UseCacheManagerCorsHandler(); app.UseCacheManagerCorsHandler();
app.UseSignalR(routes => { routes.MapHub<SignalRHub>("/NotiHub"); }); app.UseSignalR(routes => { routes.MapHub<SignalRHub>("/NotiHub"); });
app.UseRollbarMiddleware();
app.UseMvc(routes => app.UseMvc(routes =>
{ {
routes.MapRoute( routes.MapRoute(

View File

@ -12,6 +12,10 @@
"FileName": "Error\\Log.log" "FileName": "Error\\Log.log"
} }
}, },
"Rollbar": {
"AccessToken": "2fbdc15dff334a73a5542e6e82309a35",
"Environment": "AspNetCoreMiddlewareTest"
},
"ConnectionStrings": { "ConnectionStrings": {
"ba": "Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa" "ba": "Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa"
}, },