Skip to content

Commit 91eef33

Browse files
logger ui route added
1 parent 175ea58 commit 91eef33

File tree

10 files changed

+148
-34
lines changed

10 files changed

+148
-34
lines changed

TestLog/Logs/logs20210414.txt

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2021-04-14 11:51:33.452 +00:00 [INF] Application started. Press Ctrl+C to shut down.
2+
2021-04-14 11:51:33.638 +00:00 [INF] Request starting HTTP/2 GET https://localhost:44357/swagger/index.html - -
3+
2021-04-14 11:51:33.669 +00:00 [INF] Hosting environment: Development
4+
2021-04-14 11:51:33.669 +00:00 [INF] Content root path: C:\Users\cyber\RiderProjects\eazy-logger\TestLog
5+
2021-04-14 11:51:34.396 +00:00 [INF] Request finished HTTP/2 GET https://localhost:44357/swagger/index.html - - - 200 - text/html;charset=utf-8 760.1326ms
6+
2021-04-14 11:51:36.098 +00:00 [INF] Request starting HTTP/2 GET https://localhost:44357/swagger/v1/swagger.json - -
7+
2021-04-14 11:51:36.361 +00:00 [INF] Request finished HTTP/2 GET https://localhost:44357/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 262.9283ms
8+
2021-04-14 11:51:42.062 +00:00 [INF] Request starting HTTP/2 GET https://localhost:44357/swagger/v1/swagger.json - -
9+
2021-04-14 11:51:42.071 +00:00 [INF] Request finished HTTP/2 GET https://localhost:44357/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 11.3195ms
10+
2021-04-14 11:51:49.726 +00:00 [INF] Request starting HTTP/2 GET https://localhost:44357/eazy-logger-ui - -
11+
2021-04-14 11:51:49.762 +00:00 [INF] Request finished HTTP/2 GET https://localhost:44357/eazy-logger-ui - - - 301 - - 38.3495ms
12+
2021-04-14 11:51:49.788 +00:00 [INF] Request starting HTTP/2 GET https://localhost:44357/eazy-logger-ui/index.html - -
13+
2021-04-14 11:51:50.591 +00:00 [ERR] An unhandled exception has occurred while executing the request.
14+
System.ArgumentNullException: Value cannot be null. (Parameter 'stream')
15+
at System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean leaveOpen)
16+
at System.IO.StreamReader..ctor(Stream stream)
17+
at eazy.logger.ui.MiddlewareExtention.RespondWithIndexHtml(HttpResponse response) in C:\Users\cyber\RiderProjects\eazy-logger\src\eazy.logger.ui\Helper\MiddlewareExtention.cs:line 133
18+
at eazy.logger.ui.MiddlewareExtention.RespondWithIndexHtml(HttpResponse response) in C:\Users\cyber\RiderProjects\eazy-logger\src\eazy.logger.ui\Helper\MiddlewareExtention.cs:line 137
19+
at eazy.logger.ui.MiddlewareExtention.Invoke(HttpContext httpContext) in C:\Users\cyber\RiderProjects\eazy-logger\src\eazy.logger.ui\Helper\MiddlewareExtention.cs:line 98
20+
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
21+
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
22+
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
23+
2021-04-14 11:51:50.976 +00:00 [INF] Request finished HTTP/2 GET https://localhost:44357/eazy-logger-ui/index.html - - - 500 - text/html;+charset=utf-8 1187.9188ms
24+
2021-04-14 11:51:51.548 +00:00 [INF] Request starting HTTP/2 GET https://localhost:44357/favicon.ico - -
25+
2021-04-14 11:51:51.628 +00:00 [INF] Request finished HTTP/2 GET https://localhost:44357/favicon.ico - - - 404 - - 80.4396ms
26+
2021-04-14 11:53:08.338 +00:00 [INF] Request starting HTTP/2 GET https://localhost:44357/eazy-logger-ui/index.html - -
27+
2021-04-14 11:57:09.784 +00:00 [INF] Application started. Press Ctrl+C to shut down.
28+
2021-04-14 11:57:09.862 +00:00 [INF] Request starting HTTP/2 GET https://localhost:44357/swagger/index.html - -
29+
2021-04-14 11:57:09.923 +00:00 [INF] Hosting environment: Development
30+
2021-04-14 11:57:09.924 +00:00 [INF] Content root path: C:\Users\cyber\RiderProjects\eazy-logger\TestLog
31+
2021-04-14 11:57:10.648 +00:00 [INF] Request finished HTTP/2 GET https://localhost:44357/swagger/index.html - - - 200 - text/html;charset=utf-8 789.8204ms
32+
2021-04-14 11:57:11.266 +00:00 [INF] Request starting HTTP/2 GET https://localhost:44357/swagger/v1/swagger.json - -
33+
2021-04-14 11:57:11.529 +00:00 [INF] Request finished HTTP/2 GET https://localhost:44357/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 263.1021ms
34+
2021-04-14 11:57:16.964 +00:00 [INF] Request starting HTTP/2 GET https://localhost:44357/swagger/v1/swagger.json - -
35+
2021-04-14 11:57:16.973 +00:00 [INF] Request finished HTTP/2 GET https://localhost:44357/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 9.6016ms
36+
2021-04-14 11:57:57.922 +00:00 [INF] Request starting HTTP/2 GET https://localhost:44357/eazy-logger-ui/index.html - -
37+
2021-04-14 12:00:06.846 +00:00 [ERR] An unhandled exception has occurred while executing the request.
38+
System.ArgumentNullException: Value cannot be null. (Parameter 'stream')
39+
at System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean leaveOpen)
40+
at System.IO.StreamReader..ctor(Stream stream)
41+
at eazy.logger.ui.MiddlewareExtention.RespondWithIndexHtml(HttpResponse response) in C:\Users\cyber\RiderProjects\eazy-logger\src\eazy.logger.ui\Helper\MiddlewareExtention.cs:line 133
42+
at eazy.logger.ui.MiddlewareExtention.RespondWithIndexHtml(HttpResponse response) in C:\Users\cyber\RiderProjects\eazy-logger\src\eazy.logger.ui\Helper\MiddlewareExtention.cs:line 137
43+
at eazy.logger.ui.MiddlewareExtention.Invoke(HttpContext httpContext) in C:\Users\cyber\RiderProjects\eazy-logger\src\eazy.logger.ui\Helper\MiddlewareExtention.cs:line 98
44+
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
45+
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
46+
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
47+
2021-04-14 12:00:07.548 +00:00 [INF] Request finished HTTP/2 GET https://localhost:44357/eazy-logger-ui/index.html - - - 500 - text/html;+charset=utf-8 129625.7308ms
48+
2021-04-14 12:05:24.812 +00:00 [INF] Application started. Press Ctrl+C to shut down.
49+
2021-04-14 12:05:24.959 +00:00 [INF] Request starting HTTP/2 GET https://localhost:44357/swagger/index.html - -
50+
2021-04-14 12:05:24.992 +00:00 [INF] Hosting environment: Development
51+
2021-04-14 12:05:24.992 +00:00 [INF] Content root path: C:\Users\cyber\RiderProjects\eazy-logger\TestLog
52+
2021-04-14 12:05:25.663 +00:00 [INF] Request finished HTTP/2 GET https://localhost:44357/swagger/index.html - - - 200 - text/html;charset=utf-8 754.7263ms
53+
2021-04-14 12:05:26.495 +00:00 [INF] Request starting HTTP/2 GET https://localhost:44357/swagger/v1/swagger.json - -
54+
2021-04-14 12:05:26.775 +00:00 [INF] Request finished HTTP/2 GET https://localhost:44357/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 278.6522ms
55+
2021-04-14 12:05:45.677 +00:00 [INF] Request starting HTTP/2 GET https://localhost:44357/eazy.logger.ui.wwwroot.index.html - -
56+
2021-04-14 12:05:58.394 +00:00 [INF] Request finished HTTP/2 GET https://localhost:44357/eazy.logger.ui.wwwroot.index.html - - - 404 - - 12683.2635ms
57+
2021-04-14 12:06:07.834 +00:00 [INF] Request starting HTTP/2 GET https://localhost:44357/eazy.logger.ui.wwwroot.index.html - -
58+
2021-04-14 12:06:07.846 +00:00 [INF] Request finished HTTP/2 GET https://localhost:44357/eazy.logger.ui.wwwroot.index.html - - - 404 - - 11.9039ms
59+
2021-04-14 12:06:19.195 +00:00 [INF] Request starting HTTP/2 GET https://localhost:44357/eazy.logger.ui - -
60+
2021-04-14 12:06:19.196 +00:00 [INF] Request finished HTTP/2 GET https://localhost:44357/eazy.logger.ui - - - 404 - - 1.0452ms
61+
2021-04-14 12:07:11.147 +00:00 [INF] Request starting HTTP/2 GET https://localhost:44357/eazy-logger-ui/index.html - -
62+
2021-04-14 12:07:45.307 +00:00 [INF] Request finished HTTP/2 GET https://localhost:44357/eazy-logger-ui/index.html - - - 200 - text/html;charset=utf-8 34158.9372ms

TestLog/Startup.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using eazy.logger.ui;
12
using Microsoft.AspNetCore.Builder;
23
using Microsoft.AspNetCore.Hosting;
34
using Microsoft.AspNetCore.HttpsPolicy;
@@ -28,6 +29,7 @@ public void ConfigureServices(IServiceCollection services)
2829
{
2930

3031
services.AddControllers();
32+
3133
services.AddSwaggerGen(c =>
3234
{
3335
c.SwaggerDoc("v1", new OpenApiInfo { Title = "TestLog", Version = "v1" });
@@ -44,6 +46,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
4446
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "TestLog v1"));
4547
}
4648

49+
app.UseEazyLoggerUi();
50+
4751
app.UseHttpsRedirection();
4852

4953
app.UseRouting();

TestLog/TestLog.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
</ItemGroup>
1010

1111
<ItemGroup>
12+
<ProjectReference Include="..\src\eazy.logger.ui\eazy.logger.ui.csproj" />
1213
<ProjectReference Include="..\src\eazy.logger\eazy.logger.csproj" />
1314
</ItemGroup>
1415

src/eazy.logger.ui/MiddlewareExtention.cs renamed to src/eazy.logger.ui/Helper/MiddlewareExtention.cs

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ public async Task Invoke(HttpContext httpContext)
6161
try
6262
{
6363
httpContext.Response.ContentType = "application/json;charset=utf-8";
64-
//if (!CanAccess(httpContext))
65-
//{
66-
// httpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
67-
// return;
68-
//}
6964

7065
var result = await FetchLogsAsync(httpContext);
7166
httpContext.Response.StatusCode = (int)HttpStatusCode.OK;
@@ -137,8 +132,8 @@ private async Task RespondWithIndexHtml(HttpResponse response)
137132
await response.WriteAsync(htmlBuilder.ToString(), Encoding.UTF8);
138133
}
139134

140-
private Func<Stream> IndexStream { get; } = () => typeof(AuthorizationOptions).GetTypeInfo().Assembly
141-
.GetManifestResourceStream("eazy.logger.ui.wwwroot.index.html");
135+
private Func<Stream> IndexStream { get; } =
136+
() => Assembly.GetExecutingAssembly().GetManifestResourceStream("eazy.logger.ui.wwwroot.index.html");
142137

143138
private async Task<string> FetchLogsAsync(HttpContext httpContext)
144139
{
@@ -159,30 +154,5 @@ private async Task<string> FetchLogsAsync(HttpContext httpContext)
159154
var result = JsonConvert.SerializeObject(new { logs, total, count, currentPage }, _jsonSerializerOptions);
160155
return result;
161156
}
162-
163-
//private static bool CanAccess(HttpContext httpContext)
164-
//{
165-
// if (httpContext.Request.IsLocal())
166-
// return true;
167-
168-
// var authOptions = httpContext.RequestServices.GetService<AuthorizationOptions>();
169-
// if (!authOptions.Enabled)
170-
// return false;
171-
172-
// if (!httpContext.User.Identity.IsAuthenticated)
173-
// return false;
174-
175-
// var userName = httpContext.User.Identity.Name?.ToLower();
176-
// if (authOptions.Usernames != null &&
177-
// authOptions.Usernames.Any(u => u.ToLower() == userName))
178-
// return true;
179-
180-
// if (authOptions.Roles != null &&
181-
// authOptions.Roles.Any(role => httpContext.User.IsInRole(role)))
182-
// return true;
183-
184-
// return false;
185-
//}
186-
187157
}
188158
}

src/eazy.logger.ui/UIExtention.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using eazy.logger.Builders;
2+
using eazy.logger.ui.Helper;
3+
using Microsoft.AspNetCore.Builder;
4+
using Microsoft.Extensions.Configuration;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using System;
7+
using System.Linq;
8+
9+
namespace eazy.logger.ui
10+
{
11+
public static class UIExtention
12+
{
13+
public static IApplicationBuilder UseEazyUi(this IApplicationBuilder applicationBuilder, Action<UiOptions> options = null)
14+
{
15+
if (applicationBuilder == null)
16+
throw new ArgumentNullException(nameof(applicationBuilder));
17+
18+
var uiOptions = new UiOptions();
19+
options?.Invoke(uiOptions);
20+
21+
//var scope = applicationBuilder.ApplicationServices.CreateScope();
22+
//var authOptions = scope.ServiceProvider.GetService<AuthorizationOptions>();
23+
//uiOptions.AuthType = authOptions.AuthenticationType.ToString();
24+
25+
//scope.Dispose();
26+
27+
return applicationBuilder.UseMiddleware<MiddlewareExtention>(uiOptions);
28+
}
29+
}
30+
}

src/eazy.logger.ui/eazy.logger.ui.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
</ItemGroup>
1010

1111
<ItemGroup>
12-
<EmbeddedResource Include="wwwroot/index.html" />
1312
<EmbeddedResource Include="wwwroot/dist/**/*" />
1413
</ItemGroup>
1514

1615
<ItemGroup>
17-
<None Include="wwwroot\index.html" />
16+
<None Remove="wwwroot\index.html" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<EmbeddedResource Include="wwwroot\index.html" />
1821
</ItemGroup>
1922

2023
<ItemGroup>

src/eazy.logger.ui/wwwroot/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
3+
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
4+
<head>
5+
<meta charset="utf-8" />
6+
<title></title>
7+
</head>
8+
<body>
9+
hi
10+
</body>
11+
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace eazy.logger.Builders
7+
{
8+
public interface IUIOptionsBuilder
9+
{
10+
IServiceCollection Services { get; }
11+
}
12+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace eazy.logger.Builders
7+
{
8+
public class UIOptionsBuilder : IUIOptionsBuilder
9+
{
10+
private readonly IServiceCollection _services;
11+
12+
public UIOptionsBuilder(IServiceCollection services)
13+
{
14+
_services = services;
15+
}
16+
17+
IServiceCollection IUIOptionsBuilder.Services => _services;
18+
}
19+
}

src/eazy.logger/Logging/Extensions.cs renamed to src/eazy.logger/Extensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using eazy.logger.Logging.Options;
5+
using Microsoft.AspNetCore.Builder;
56
using Microsoft.Extensions.Configuration;
67
using Microsoft.Extensions.Hosting;
78
using Serilog;
@@ -89,6 +90,7 @@ in options.MinimumLevelOverrides
8990
});
9091
}
9192

93+
9294
private static void MapOptions(LoggerOptions loggerOptions, string appOptions,
9395
LoggerConfiguration loggerConfig, string environmentName)
9496
{

0 commit comments

Comments
 (0)