+
Skip to content

init log stream #670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,245 changes: 1,155 additions & 1,090 deletions src/applications/Mixcore/wwwroot/mix-app/js/app-portal.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div class="page-wrapper d-flex flex-column pt-4"><div class="container-xl"><div class="page-header d-print-none"><div class="row align-items-center"><div class="col"><div class="page-pretitle">Listing</div><h3 class="page-title">All Audit Logs</h3></div></div></div></div><div class="page-body d-flex flex-row-reverse"><aside class="bd-sidebar sub-sidebar"><nav class="bd-links p-3" aria-label="Sub-section navigation"><div class="card card-body"><filter-list class="" request="request" callback="getList(pageIndex)"></filter-list></div></nav></aside><div class="content-body py-3 pe-3"><div class="card mb-5"><div class="card-body"><table id="list-page" class="table table-striped-x table-hover" dnd-list="data.items" dnd-disable-if="canDrag" cellspacing="0" ng-init="getList()"><thead class="thead-light"><tr><th scope="col" width="15px"><div class="form-check m-0 p-0"><input type="checkbox" class="form-check-inputx" ng-model="selectedList.isSelectAll" ng-change="selectAll(selectedList.isSelectAll)" id="customCheck_all"></div></th><th class="col">Endpoint</th><th class="col">Request Ip</th><th class="col">Created</th><th class="col">Created By</th><th class="col"></th><th class="col text-end"></th></tr></thead><tbody class=""><tr ng-repeat="item in data.items track by $index" dnd-draggable="item" dnd-effect-allowed="move" dnd-selected="selected = item" dnd-moved="updateInfos($index)" ng-class="{'selected': selected === item}" class="" sort-model="category" sort-model-id="{{item.id}}"><td class="align-middle"><div class="form-check"><input type="checkbox" class="form-check-input" id="customCheck_{{item.id}}" ng-model="item.isSelected" ng-change="select(item.id, item.isSelected)"> <label class="custom-control-label" for="customCheck_{{item.id}}"></label></div></td><td class=""><a href="" ng-click="view(item)" class="btn-link" ng-bind="item.endpoint|trim:50"></a></td><td><span ng-bind="item.requestIp|trim:50"></span></td><td class="text-secondary"><small>{{item.createdDateTime | utcToLocal:'dd.MM.yy hh:mm a'}}</small></td><td class="text-secondary"><small>{{item.createdBy}}</small></td><td><a class="dropdown-item border-radius-md" ng-click="view(item)"><span class="fa fa-eye"></span></a></td><td class="text-black-50"><small ng-if="item.status == 'Published'">🟢</small> <small ng-if="item.status == 'Schedule'">🟡</small> <small ng-if="item.status == 'Draft'">🔴</small> <small ng-if="item.status == 'Deleted'">⚫️</small></td></tr></tbody></table></div><div class="card-body"><paging class="small" page="data.pagingData.page" page-size="data.pagingData.pageSize" total="data.pagingData.total" ul-class="pagination justify-content-end m-0" a-class="page-link" paging-action="getList(page-1)" scroll-top="true"></paging></div></div></div></div></div>
<div class="page-wrapper d-flex flex-column pt-4"><div class="container-xl"><div class="page-header d-print-none"><div class="row align-items-center"><div class="col"><div class="page-pretitle">Listing</div><h3 class="page-title">All Audit Logs</h3><div><a href="/admin/audit-log/stream" class="btn-link btn-primary">Log Streams</a></div></div></div></div></div><div class="page-body d-flex flex-row-reverse"><aside class="bd-sidebar sub-sidebar"><nav class="bd-links p-3" aria-label="Sub-section navigation"><div class="card card-body"><filter-list class="" request="request" callback="getList(pageIndex)"></filter-list></div></nav></aside><div class="content-body py-3 pe-3"><div class="card mb-5"><div class="card-body"><table id="list-page" class="table table-striped-x table-hover" dnd-list="data.items" dnd-disable-if="canDrag" cellspacing="0" ng-init="getList()"><thead class="thead-light"><tr><th scope="col" width="15px"><div class="form-check m-0 p-0"><input type="checkbox" class="form-check-inputx" ng-model="selectedList.isSelectAll" ng-change="selectAll(selectedList.isSelectAll)" id="customCheck_all"></div></th><th class="col">Endpoint</th><th class="col">Request Ip</th><th class="col">Created</th><th class="col">Created By</th><th class="col"></th><th class="col text-end"></th></tr></thead><tbody class=""><tr ng-repeat="item in data.items track by $index" dnd-draggable="item" dnd-effect-allowed="move" dnd-selected="selected = item" dnd-moved="updateInfos($index)" ng-class="{'selected': selected === item}" class="" sort-model="category" sort-model-id="{{item.id}}"><td class="align-middle"><div class="form-check"><input type="checkbox" class="form-check-input" id="customCheck_{{item.id}}" ng-model="item.isSelected" ng-change="select(item.id, item.isSelected)"> <label class="custom-control-label" for="customCheck_{{item.id}}"></label></div></td><td class=""><a href="" ng-click="view(item)" class="btn-link" ng-bind="item.endpoint|trim:50"></a></td><td><span ng-bind="item.requestIp|trim:50"></span></td><td class="text-secondary"><small>{{item.createdDateTime | utcToLocal:'dd.MM.yy hh:mm a'}}</small></td><td class="text-secondary"><small>{{item.createdBy}}</small></td><td><a class="dropdown-item border-radius-md" ng-click="view(item)"><span class="fa fa-eye"></span></a></td><td class="text-black-50"><small ng-if="item.status == 'Published'">🟢</small> <small ng-if="item.status == 'Schedule'">🟡</small> <small ng-if="item.status == 'Draft'">🔴</small> <small ng-if="item.status == 'Deleted'">⚫️</small></td></tr></tbody></table></div><div class="card-body"><paging class="small" page="data.pagingData.page" page-size="data.pagingData.pageSize" total="data.pagingData.total" ul-class="pagination justify-content-end m-0" a-class="page-link" paging-action="getList(page-1)" scroll-top="true"></paging></div></div></div></div></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="page-wrapper d-flex flex-column pt-4 w-100" ng-init="connect()"><div><div class="page-body d-flex flex-row-reverse"><div class="content-body py-3 pe-3"><section class="pt-4 pb-3"><div class="row" id="log-stream-container"><table class="table table-sm table-hover sortable" cellspacing="0"><thead class="thead-light"><tr><th scope="col" width="15%">From</th><th scope="col" width="10%">Status</th><th scope="col">Title</th><th scope="col">Message</th><th width="30%" scope="col">Data</th><th scope="col">Created Date</th></tr></thead><tbody><tr ng-repeat="msg in messages"><td><span ng-bind="msg.from.username" class="text-{{msg.style}}"></span></td><td><span ng-bind="msg.type" class="text-{{msg.style}}"></span></td><td><span ng-bind="msg.title" class="text-{{msg.style}}"></span></td><td><span ng-bind="msg.message" class="text-{{msg.style}}"></span></td><td><pre ng-bind="msg.data | json" class="text-{{msg.style}}"></pre></td><td><span ng-bind="msg.createdDateTime | utcToLocal" class="text-{{msg.style}}"></span></td></tr></tbody></table></div></section></div></div></div></div>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static IApplicationBuilder UseMixSignalRApp(this IApplicationBuilder app)
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<PortalHub>(HubEndpoints.PortalHub);
endpoints.MapHub<LogStreamHub>(HubEndpoints.LogStreamHub);
endpoints.MapHub<EditFileHub>(HubEndpoints.EditFileHub);
endpoints.MapHub<MixThemeHub>(HubEndpoints.MixThemeHub);
endpoints.MapHub<HighFrequencyHub>(HubEndpoints.HighFrequencyHub);
Expand Down
5 changes: 3 additions & 2 deletions src/platform/mix.communicator/Services/EmailService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Extensions.Configuration;
using Mix.Communicator.Models;
using Mix.Heart.Exceptions;
using Mix.Service.Services;
using System.Net;
using System.Net.Mail;
Expand Down Expand Up @@ -41,9 +42,9 @@ public async Task SendMail(EmailMessageModel msg)

await client.SendMailAsync(mailMessage);
}
catch (Exception e)
catch (Exception ex)
{
MixService.LogException(e);
throw new MixException(Heart.Enums.MixErrorStatus.ServerError, ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ public void OnActionExecuted(ActionExecutedContext context)
},
};
context.ExceptionHandled = true;
MixLogService.LogExceptionAsync(context.Exception).GetAwaiter().GetResult();
}
else if (context.Exception != null)
{
context.Result = new BadRequestObjectResult(context.Exception.Message?.Split('\n'));
MixLogService.LogExceptionAsync(context.Exception).GetAwaiter().GetResult();
}
context.ExceptionHandled = true;

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private async Task ShareTransaction(HttpContext context,
}
catch (Exception ex)
{
MixService.LogException(ex, message: "Cannot share connections");
MixLogService.LogExceptionAsync(ex, message: "Cannot share connections");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/platform/mix.library/Services/MixIdentityService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public async Task<JObject> GetOrCreateUserData(MixUser user, CancellationToken c
}
catch (Exception ex)
{
MixService.LogException(ex);
MixLogService.LogExceptionAsync(ex);
return ReflectionHelper.ParseObject(new
{
ParentId = user.Id,
Expand Down
4 changes: 2 additions & 2 deletions src/platform/mix.library/Startup/ExceptionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ public static void ConfigureExceptionHandler(this IApplicationBuilder app)
app.UseDeveloperExceptionPage();
app.UseExceptionHandler(appError =>
{
appError.Run((context) =>
appError.Run(async (context) =>
{
var contextFeature = context.Features.Get<IExceptionHandlerFeature>();
if (contextFeature != null)
{
throw new MixException(MixErrorStatus.ServerError, contextFeature.Error);
}
return Task.CompletedTask;
await MixLogService.LogExceptionAsync(contextFeature.Error);
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Mix.Shared;
using Mix.Shared.Interfaces;
using Mix.SignalR.Interfaces;
using Mix.SignalR.Services;
using System.Reflection;

namespace Microsoft.Extensions.DependencyInjection
Expand Down Expand Up @@ -104,6 +103,7 @@ public static IServiceCollection AddMixTestServices(this IServiceCollection serv
services.TryAddSingleton<IAuditLogService, AuditLogService>();
services.TryAddSingleton<IMixMemoryCacheService, MixMemoryCacheService>();
services.TryAddSingleton<IPortalHubClientService, PortalHubClientService>();
services.TryAddSingleton<ILogStreamHubClientService, LogStreamHubClientService>();
services.AddMixRepoDb();
return services;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public override async Task Handler(MessageQueueModel model)
case MixQueueActions.AuditLog:
var cmd = model.ParseData<LogAuditLogCommand>();
AuditLogService.SaveToDatabase(cmd.UserName, cmd.Request, true, null);
await MixLogService.LogMessageAsync(cmd.UserName, data: cmd.Request);
break;
case MixQueueActions.SendMail:
await SendMail(model);
Expand All @@ -59,7 +60,7 @@ private async Task SendMail(MessageQueueModel model)
}
catch (Exception ex)
{
MixService.LogException(ex);
MixLogService.LogExceptionAsync(ex);
await SendMessage($"Error {model.Action}: {model.Data}", false, ex);
}

Expand All @@ -73,7 +74,6 @@ private async Task SendMessage(string message, bool result, Exception? ex = null
Type = result ? MessageType.Success : MessageType.Error,
Title = message,
From = new(GetType().FullName),
Data = result,
Message = ex == null ? message : ex!.Message
};
await PortalHub.SendMessageAsync(msg);
Expand Down
4 changes: 2 additions & 2 deletions src/platform/mix.library/ViewModels/MixUserViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ on ur.RoleId equals r.Id
}
catch (Exception ex)
{
MixService.LogException(ex);
MixLogService.LogExceptionAsync(ex);
}
}
}
Expand All @@ -122,7 +122,7 @@ public async Task LoadUserPortalMenus(string[] roles, int tenantId, MixRepoDbRep
}
catch (Exception ex)
{
MixService.LogException(ex);
MixLogService.LogExceptionAsync(ex);
PortalMenus = new();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public override void Configure(EntityTypeBuilder<MixPermission> builder)
}
catch (Exception ex)
{
MixService.LogException(ex);
MixLogService.LogExceptionAsync(ex);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/mix.mixdb/Services/RuntimeDbContextService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void LoadDbContextAssembly()

var error = failures.FirstOrDefault();
//throw new Exception($"{error?.Id}: {error?.GetMessage()}");
MixService.LogException(new Exception($"{error?.Id}: {error?.GetMessage()}"));
MixLogService.LogExceptionAsync(new Exception($"{error?.Id}: {error?.GetMessage()}"));
}
_assemblyLoadContext = new AssemblyLoadContext("DataContext", isCollectible: true);

Expand Down
1 change: 1 addition & 0 deletions src/platform/mix.mixdb/mix.mixdb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<ItemGroup>
<ProjectReference Include="..\mix.database\mix.database.csproj" />
<ProjectReference Include="..\mix.service\mix.service.csproj" />
<Using Include="Mix.Mixdb.Entities" />
<Using Include="Mix.Mixdb.Entities" />
</ItemGroup>
Expand Down
36 changes: 11 additions & 25 deletions src/platform/mix.queue/Engines/SubscriberBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public abstract class SubscriberBase : IHostedService
private readonly string _topicId;

protected readonly IServiceProvider ServicesProvider;
protected IServiceScope ServiceScope { get; set ; }
protected IServiceScope ServiceScope { get; set; }
protected SubscriberBase(
string topicId,
string moduleName,
Expand Down Expand Up @@ -92,41 +92,27 @@ private IQueueSubscriber CreateSubscriber(string topicId, string subscriptionId)
return default;
}

//protected IServiceScope GetServiceScope()
//{
// if (_serviceScope == null)
// {
// _serviceScope = _servicesProvider.CreateScope();
// }
// return _serviceScope;
//}

protected T GetScopedService<T>()
{
return ServiceScope.ServiceProvider.GetRequiredService<T>();
}

public Task MessageHandler(MessageQueueModel data)
{

try
{
if (_topicId != data.TopicId)
{
return Task.CompletedTask;
}

return Handler(data);
}
catch (Exception ex)
try
{
if (_topicId != data.TopicId)
{
MixService.LogException(ex);
return Task.CompletedTask;
}
//finally
//{
// _serviceScope?.Dispose();
//}

return Handler(data);
}
catch (Exception ex)
{
throw new MixException(Heart.Enums.MixErrorStatus.ServerError, ex);
}
}

public abstract Task Handler(MessageQueueModel model);
Expand Down
18 changes: 9 additions & 9 deletions src/platform/mix.repodb/Repositories/MixRepoDbRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private Operation ParseMixOperator(MixCompareOperator compareOperator)
}
catch (Exception ex)
{
MixService.LogException(ex);
await MixLogService.LogExceptionAsync(ex);
return default;
}
finally
Expand All @@ -238,7 +238,7 @@ private Operation ParseMixOperator(MixCompareOperator compareOperator)
}
catch (Exception ex)
{
MixService.LogException(ex);
await MixLogService.LogExceptionAsync(ex);
return default;
}
finally
Expand All @@ -265,7 +265,7 @@ private Operation ParseMixOperator(MixCompareOperator compareOperator)
}
catch (Exception ex)
{
MixService.LogException(ex);
await MixLogService.LogExceptionAsync(ex);
return default;
}
finally
Expand Down Expand Up @@ -293,7 +293,7 @@ private Operation ParseMixOperator(MixCompareOperator compareOperator)
}
catch (Exception ex)
{
MixService.LogException(ex);
await MixLogService.LogExceptionAsync(ex);
return default;
}
finally
Expand Down Expand Up @@ -323,7 +323,7 @@ public async Task InsertAsync(JObject entity)
}
catch (Exception ex)
{
throw new MixException(MixErrorStatus.Badrequest, ex.Message);
throw new MixException(MixErrorStatus.Badrequest, ex);
}
finally
{
Expand All @@ -346,7 +346,7 @@ public async Task InsertAsync(JObject entity)
}
catch (Exception ex)
{
MixService.LogException(ex);
await MixLogService.LogExceptionAsync(ex);
return default;
}
finally
Expand Down Expand Up @@ -375,7 +375,7 @@ public async Task InsertAsync(JObject entity)
}
catch (Exception ex)
{
MixService.LogException(ex);
await MixLogService.LogExceptionAsync(ex);
return default;
}
finally
Expand All @@ -400,7 +400,7 @@ public async Task<int> DeleteAsync(int id)
}
catch (Exception ex)
{
MixService.LogException(ex);
await MixLogService.LogExceptionAsync(ex);
return default;
}
finally
Expand All @@ -425,7 +425,7 @@ public async Task<int> DeleteAsync(List<QueryField> queries)
}
catch (Exception ex)
{
MixService.LogException(ex);
await MixLogService.LogExceptionAsync(ex);
return default;
}
finally
Expand Down
1 change: 0 additions & 1 deletion src/platform/mix.repodb/Subscribers/MixRepoDbSubscriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ private async Task SendMessage(string message, bool result, Exception? ex = null
Type = result ? MessageType.Success : MessageType.Error,
Title = message,
From = new(GetType().FullName),
Data = result,
Message = ex == null ? message : ex!.Message
};
await PortalHub.SendMessageAsync(msg);
Expand Down
2 changes: 1 addition & 1 deletion src/platform/mix.service/Services/AuditLogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void SaveToDatabase(string createdBy, ParsedRequestModel request, bool is
}
catch (Exception ex)
{
MixService.LogException(ex);
MixLogService.LogExceptionAsync(ex).GetAwaiter().GetResult();
}
}

Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载