Skip to content

Commit 36e7485

Browse files
committed
Add UI controller, view and asset files.
1 parent 22274e6 commit 36e7485

File tree

16 files changed

+187
-12
lines changed

16 files changed

+187
-12
lines changed

src/Serilog.Ui.MsSqlServerProvider/Extensions/DataProviderOptionsBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static void UseSqlServer(
1010
this DataProviderOptionsBuilder optionsBuilder,
1111
string connectionString,
1212
string tableName,
13-
string schemaName = null
13+
string schemaName = "dbo"
1414
)
1515
{
1616
if (string.IsNullOrEmpty(connectionString))

src/Serilog.Ui.MsSqlServerProvider/SqlServerDataProvider.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,33 @@ public SqlServerDataProvider(RelationalDbOptions options)
2020
{
2121
using (IDbConnection connection = new SqlConnection(_options.ConnectionString))
2222
{
23-
var logsTask = GetLogsAsync(connection, page - 1, count);
24-
var logCountTask = CountLogsAsync(connection);
23+
var logsTask = GetLogsAsync(page - 1, count);
24+
var logCountTask = CountLogsAsync();
2525

2626
await Task.WhenAll(logsTask, logCountTask);
2727

2828
return (await logsTask, await logCountTask);
2929
}
3030
}
3131

32-
private Task<IEnumerable<LogModel>> GetLogsAsync(IDbConnection connection, int page, int count)
32+
private async Task<IEnumerable<LogModel>> GetLogsAsync(int page, int count)
3333
{
3434
var query =
3535
$"SELECT [Id], [Message],[Level], [TimeStamp], [Exception], [Properties] FROM [{_options.Schema}].[{_options.TableName}] " +
3636
"ORDER BY Id DESC OFFSET @Offset ROWS FETCH NEXT @Count ROWS ONLY";
37-
38-
return connection.QueryAsync<LogModel>(query, new { page, count });
37+
using (IDbConnection connection = new SqlConnection(_options.ConnectionString))
38+
{
39+
return await connection.QueryAsync<LogModel>(query, new { Offset = page, Count = count });
40+
}
3941
}
4042

41-
public async Task<int> CountLogsAsync(IDbConnection connection)
43+
public async Task<int> CountLogsAsync()
4244
{
4345
var query = $"SELECT COUNT(Id) FROM [{_options.Schema}].[{_options.TableName}]";
44-
45-
return await connection.ExecuteScalarAsync<int>(query);
46+
using (IDbConnection connection = new SqlConnection(_options.ConnectionString))
47+
{
48+
return await connection.ExecuteScalarAsync<int>(query);
49+
}
4650
}
4751
}
4852
}

src/Serilog.Ui.Web/Extensions/ServiceCollectionExtensions.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
using Microsoft.Extensions.DependencyInjection;
1+
using Microsoft.AspNetCore.Mvc.ApplicationParts;
2+
using Microsoft.Extensions.DependencyInjection;
23
using Serilog.Ui.Core;
34
using System;
5+
using System.Linq;
46

57
namespace Serilog.Ui.Web
68
{
79
public static class ServiceCollectionExtensions
810
{
9-
public static IServiceCollection AddSerilogUi(this IServiceCollection services, Action<DataProviderOptionsBuilder> optionsBuilder)
11+
public static IServiceCollection AddSerilogUi(
12+
this IServiceCollection services,
13+
IMvcBuilder mvcBuilder,
14+
Action<DataProviderOptionsBuilder> optionsBuilder)
1015
{
1116
if (services == null)
1217
throw new ArgumentNullException(nameof(services));
@@ -17,7 +22,29 @@ public static IServiceCollection AddSerilogUi(this IServiceCollection services,
1722
var builder = new DataProviderOptionsBuilder(services);
1823
optionsBuilder.Invoke(builder);
1924

25+
//var assembly = typeof(ServiceCollectionExtensions).Assembly;
26+
// var location = assembly.Location;
27+
//var embeddedFileProvider = new EmbeddedFileProvider(assembly);
28+
//mvcBuilder.AddRazorRuntimeCompilation(options => options.FileProviders.Add(embeddedFileProvider));
29+
30+
var assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.StartsWith("Serilog.Ui.Web")).ToList();
31+
foreach (var assembly in assemblies)
32+
{
33+
if (assembly.FullName.Contains("Views"))
34+
mvcBuilder.PartManager.ApplicationParts.Add(new CompiledRazorAssemblyPart(assembly));
35+
else
36+
{
37+
mvcBuilder.PartManager.ApplicationParts.Add(new AssemblyPart(assembly));
38+
var manifestResourceNames = assembly.GetManifestResourceNames();
39+
}
40+
}
41+
2042
return services;
2143
}
44+
45+
private static void ConfigureApplicationParts(ApplicationPartManager apm)
46+
{
47+
apm.ApplicationParts.Add(new AssemblyPart(typeof(ServiceCollectionExtensions).Assembly));
48+
}
2249
}
2350
}

src/Serilog.Ui.Web/Serilog.Ui.Web.csproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
6+
<RazorCompileOnBuild>true</RazorCompileOnBuild>
57
</PropertyGroup>
68

79
<ItemGroup>
810
<FrameworkReference Include="Microsoft.AspNetCore.App" />
911
</ItemGroup>
1012

13+
<ItemGroup>
14+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.3" />
15+
</ItemGroup>
16+
1117
<ItemGroup>
1218
<ProjectReference Include="..\Serilog.Ui.Core\Serilog.Ui.Core.csproj" />
1319
</ItemGroup>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@using Microsoft.AspNetCore.Http
2+
@model LogViewModel
3+
@{
4+
ViewData["Title"] = "Log List";
5+
Layout = "~/Views/Shared/_LogLayout.cshtml";
6+
}
7+
<h1>Log List</h1>
8+
9+
<p>Use this page to detail your site's privacy policy.</p>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>@ViewData["Title"] - SampleWebApplication</title>
7+
<link rel="stylesheet" href="~/css/bootstrap.min.css" />
8+
<link rel="stylesheet" href="~/css/log.css" />
9+
</head>
10+
<body>
11+
<header>
12+
</header>
13+
<div class="container">
14+
<main role="main" class="pb-3">
15+
@RenderBody()
16+
</main>
17+
</div>
18+
19+
<footer class="border-top footer text-muted">
20+
<div class="container">
21+
&copy; @DateTime.Now.Year - <a href="https://github.com/mo-esmp/serilog-ui" target="_blank">Serilog UI</a>
22+
</div>
23+
</footer>
24+
<script src="~/js/jquery.min.js"></script>
25+
<script src="~/js/bootstrap.bundle.min.js"></script>
26+
<script src="~/js/log.js" asp-append-version="true"></script>
27+
@RenderSection("Scripts", required: false)
28+
</body>
29+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@using Serilog.Ui.Web
2+
@using Serilog.Ui.Web.ViewModel
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

src/Serilog.Ui.Web/wwwroot/css/bootstrap.min.css

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Serilog.Ui.Web/wwwroot/css/bootstrap.min.css.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2+
for details on configuring this project to bundle and minify static web assets. */
3+
4+
a.navbar-brand {
5+
white-space: normal;
6+
text-align: center;
7+
word-break: break-all;
8+
}
9+
10+
/* Provide sufficient contrast against white background */
11+
a {
12+
color: #0366d6;
13+
}
14+
15+
.btn-primary {
16+
color: #fff;
17+
background-color: #1b6ec2;
18+
border-color: #1861ac;
19+
}
20+
21+
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
22+
color: #fff;
23+
background-color: #1b6ec2;
24+
border-color: #1861ac;
25+
}
26+
27+
/* Sticky footer styles
28+
-------------------------------------------------- */
29+
html {
30+
font-size: 14px;
31+
}
32+
33+
@media (min-width: 768px) {
34+
html {
35+
font-size: 16px;
36+
}
37+
}
38+
39+
.border-top {
40+
border-top: 1px solid #e5e5e5;
41+
}
42+
43+
.border-bottom {
44+
border-bottom: 1px solid #e5e5e5;
45+
}
46+
47+
.box-shadow {
48+
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
49+
}
50+
51+
button.accept-policy {
52+
font-size: 1rem;
53+
line-height: inherit;
54+
}
55+
56+
/* Sticky footer styles
57+
-------------------------------------------------- */
58+
html {
59+
position: relative;
60+
min-height: 100%;
61+
}
62+
63+
body {
64+
/* Margin bottom by footer height */
65+
margin-bottom: 60px;
66+
}
67+
68+
.footer {
69+
position: absolute;
70+
bottom: 0;
71+
width: 100%;
72+
white-space: nowrap;
73+
line-height: 60px; /* Vertically center the text there */
74+
}

0 commit comments

Comments
 (0)