Skip to content

Commit 9936673

Browse files
committed
Support to extend the middleware based on kestrel http
1 parent 5edd62e commit 9936673

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/Surging.Core/Surging.Core.KestrelHttpServer/KestrelHttpMessageListener.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private void AppResolve(IApplicationBuilder app)
132132
_moduleProvider.Initialize(new ApplicationInitializationContext(app, _moduleProvider.Modules,
133133
_moduleProvider.VirtualPaths,
134134
AppConfig.Configuration));
135-
app.Run(async (context) =>
135+
app.Use(async (context,next) =>
136136
{
137137
var messageId = Guid.NewGuid().ToString("N");
138138
var subject = new ReplaySubject<HttpResultMessage<object>>();
@@ -146,6 +146,7 @@ private void AppResolve(IApplicationBuilder app)
146146
var actionFilters = app.ApplicationServices.GetServices<IActionFilter>();
147147
await OnReceived(sender, messageId, context, actionFilters, subject);
148148
}
149+
await next();
149150
}
150151
catch (Exception ex)
151152
{
@@ -154,6 +155,7 @@ private void AppResolve(IApplicationBuilder app)
154155
await OnException(context, sender, messageId, ex, filters);
155156
}
156157
});
158+
app.Run( context=> Task.CompletedTask);
157159
}
158160

159161
private void WirteDiagnosticError(string messageId,Exception ex)

src/Surging.Core/Surging.Core.NLog/NLogger.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ public void Log<TState>(Microsoft.Extensions.Logging.LogLevel logLevel, EventId
6262
switch (logLevel)
6363
{
6464
case LogLevel.Critical:
65-
_log.Fatal(message);
65+
_log.Fatal(exception, message);
6666
break;
6767
case LogLevel.Debug:
68-
_log.Debug(message);
68+
_log.Debug(exception, message);
6969
break;
7070
case LogLevel.Trace:
71-
_log.Trace(message);
71+
_log.Trace(exception, message);
7272
break;
7373
case LogLevel.Error:
74-
_log.Error(message, exception,null);
74+
_log.Error(exception, message);
7575
break;
7676
case LogLevel.Information:
7777
_log.Info(message);
@@ -81,7 +81,7 @@ public void Log<TState>(Microsoft.Extensions.Logging.LogLevel logLevel, EventId
8181
break;
8282
default:
8383
_log.Warn($"遇到未知日志级别{logLevel}");
84-
_log.Info(message, exception,null);
84+
_log.Info(message, exception, null);
8585
break;
8686
}
8787
}

src/Surging.Modules/Surging.Modules.Common/Domain/UserService.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
using Microsoft.Extensions.Logging;
23
using Surging.Core.Common;
34
using Surging.Core.CPlatform;
45
using Surging.Core.CPlatform.EventBus.Events;
@@ -30,9 +31,11 @@ public class UserService : ProxyServiceBase, IUserService
3031
{
3132
#region Implementation of IUserService
3233
private readonly UserRepository _repository;
33-
public UserService(UserRepository repository)
34+
private readonly ILogger<UserService> _logger;
35+
public UserService(UserRepository repository,ILogger<UserService> logger)
3436
{
3537
this._repository = repository;
38+
_logger = logger;
3639
}
3740

3841
public async Task<string> GetUserName(int id)
@@ -86,6 +89,7 @@ public Task<bool> Update(int id, UserModel model)
8689

8790
public Task<bool> GetDictionary()
8891
{
92+
_logger.LogError("测试");
8993
return Task.FromResult<bool>(true);
9094
}
9195

0 commit comments

Comments
 (0)