Skip to content

Commit f148adb

Browse files
author
laxmikant
committed
initial update
1 parent 53cd826 commit f148adb

File tree

136 files changed

+77766
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+77766
-0
lines changed

ASPNETCoreMVCSerilog.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32728.150
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASPNETCoreMVCSerilog", "ASPNETCoreMVCSerilog\ASPNETCoreMVCSerilog.csproj", "{1938FD17-2711-4BE5-9487-78142644F4A2}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{1938FD17-2711-4BE5-9487-78142644F4A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{1938FD17-2711-4BE5-9487-78142644F4A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{1938FD17-2711-4BE5-9487-78142644F4A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{1938FD17-2711-4BE5-9487-78142644F4A2}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {A43CC077-43A4-41D6-AD0F-0CF327E11053}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
11+
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
12+
<PackageReference Include="Serilog.Enrichers.GlobalLogContext" Version="2.1.0" />
13+
<PackageReference Include="Serilog.Enrichers.Process" Version="2.0.2" />
14+
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
15+
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
16+
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
17+
<PackageReference Include="Serilog.Sinks.Seq" Version="5.2.0" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<Folder Include="logs\" />
22+
</ItemGroup>
23+
24+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using ASPNETCoreMVCSerilog.Models;
2+
using Microsoft.AspNetCore.Mvc;
3+
using System.Diagnostics;
4+
using System.Text;
5+
6+
namespace ASPNETCoreMVCSerilog.Controllers
7+
{
8+
public class HomeController : Controller
9+
{
10+
private readonly ILogger<HomeController> _logger;
11+
12+
public HomeController(ILogger<HomeController> logger)
13+
{
14+
_logger = logger;
15+
}
16+
17+
public IActionResult Index()
18+
{
19+
20+
//_logger.LogInformation("Index from HomeController called");
21+
//Customer customer = new Customer();
22+
//customer.CustomerID = 1;
23+
//customer.CustomerName = "Scott";
24+
//_logger.LogInformation("Processing {@customer}", customer);
25+
//int id = -1;
26+
//try
27+
//{
28+
// if (id <= 0)
29+
// {
30+
// throw new Exception($"id cannot be less than or equal to 0:{id}");
31+
// }
32+
33+
// return Ok($"id is:{id}");
34+
35+
//}
36+
//catch (Exception ex)
37+
//{
38+
// var sb = new StringBuilder();
39+
// sb.AppendLine($"Error message:{ex.Message}");
40+
// sb.AppendLine($"Error stack trace:{ex.StackTrace}");
41+
// //_logger.LogError(sb.ToString());
42+
// _logger.LogError(ex, sb.ToString());
43+
//}
44+
return View();
45+
}
46+
47+
public IActionResult Privacy()
48+
{
49+
return View();
50+
}
51+
52+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
53+
public IActionResult Error()
54+
{
55+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
56+
}
57+
}
58+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace ASPNETCoreMVCSerilog.Models
2+
{
3+
public class Customer
4+
{
5+
public int CustomerID { get; set; }
6+
7+
public string CustomerName { get; set; } = string.Empty;
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace ASPNETCoreMVCSerilog.Models
2+
{
3+
public class ErrorViewModel
4+
{
5+
public string? RequestId { get; set; }
6+
7+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
8+
}
9+
}

ASPNETCoreMVCSerilog/Program.cs

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using Serilog;
2+
using System.Diagnostics;
3+
4+
var builder = WebApplication.CreateBuilder(args);
5+
6+
// Add services to the container.
7+
builder.Services.AddControllersWithViews();
8+
9+
builder.Host.UseSerilog((ctx, lc) => lc.ReadFrom.Configuration(ctx.Configuration));
10+
11+
//var _logger = new LoggerConfiguration()
12+
// .Enrich.FromGlobalLogContext()
13+
// .WriteTo.File("./logs/log-.txt", rollingInterval: RollingInterval.Day)
14+
// .WriteTo.Seq("http://localhost:5341", Serilog.Events.LogEventLevel.Warning)
15+
// .Enrich.WithProperty("ServiceName", "SomeConsumer")
16+
// .MinimumLevel.Debug()
17+
// .CreateLogger();
18+
19+
//var _logger = new LoggerConfiguration()
20+
// .Enrich.FromLogContext()
21+
// .Enrich.WithProcessId()
22+
// .Enrich.WithProcessName()
23+
// .Enrich.WithProperty("CustomerKey", "ABC123")
24+
// .WriteTo.File("./logs/log-.txt", rollingInterval: RollingInterval.Day)
25+
// .CreateLogger();
26+
27+
28+
//var _logger = new LoggerConfiguration()
29+
// .Enrich.FromLogContext()
30+
// .Enrich.WithProcessId()
31+
// .Enrich.WithProcessName()
32+
// .Enrich.WithProperty("CustomerKey", "ABC123")
33+
// .Enrich.WithProperty("PID", Process.GetCurrentProcess().Id) // 9840
34+
// .WriteTo.File("./logs/log-.txt", rollingInterval: RollingInterval.Day,
35+
// outputTemplate: "{Timestamp:HH:mm:ss} {Message} {CustomerKey} {PID}{NewLine}{Exception}"
36+
// )
37+
// .CreateLogger();
38+
39+
40+
//builder.Logging.AddSerilog(_logger);
41+
var app = builder.Build();
42+
43+
// Configure the HTTP request pipeline.
44+
if (!app.Environment.IsDevelopment())
45+
{
46+
app.UseExceptionHandler("/Home/Error");
47+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
48+
app.UseHsts();
49+
}
50+
51+
app.UseHttpsRedirection();
52+
app.UseStaticFiles();
53+
54+
app.UseSerilogRequestLogging();
55+
56+
app.UseRouting();
57+
58+
app.UseAuthorization();
59+
60+
app.MapControllerRoute(
61+
name: "default",
62+
pattern: "{controller=Home}/{action=Index}/{id?}");
63+
64+
app.Run();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:51180",
7+
"sslPort": 44376
8+
}
9+
},
10+
"profiles": {
11+
"ASPNETCoreMVCSerilog": {
12+
"commandName": "Project",
13+
"dotnetRunMessages": true,
14+
"launchBrowser": true,
15+
"applicationUrl": "https://localhost:7233;http://localhost:5233",
16+
"environmentVariables": {
17+
"ASPNETCORE_ENVIRONMENT": "Development"
18+
}
19+
},
20+
"IIS Express": {
21+
"commandName": "IISExpress",
22+
"launchBrowser": true,
23+
"environmentVariables": {
24+
"ASPNETCORE_ENVIRONMENT": "Development"
25+
}
26+
}
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@{
2+
ViewData["Title"] = "Home Page";
3+
}
4+
5+
<div class="text-center">
6+
<h1 class="display-4">Welcome</h1>
7+
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
8+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@{
2+
ViewData["Title"] = "Privacy Policy";
3+
}
4+
<h1>@ViewData["Title"]</h1>
5+
6+
<p>Use this page to detail your site's privacy policy.</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@model ErrorViewModel
2+
@{
3+
ViewData["Title"] = "Error";
4+
}
5+
6+
<h1 class="text-danger">Error.</h1>
7+
<h2 class="text-danger">An error occurred while processing your request.</h2>
8+
9+
@if (Model.ShowRequestId)
10+
{
11+
<p>
12+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
13+
</p>
14+
}
15+
16+
<h3>Development Mode</h3>
17+
<p>
18+
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
19+
</p>
20+
<p>
21+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
22+
It can result in displaying sensitive information from exceptions to end users.
23+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
24+
and restarting the app.
25+
</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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"] - ASPNETCoreMVCSerilog</title>
7+
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
8+
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
9+
<link rel="stylesheet" href="~/ASPNETCoreMVCSerilog.styles.css" asp-append-version="true" />
10+
</head>
11+
<body>
12+
<header>
13+
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
14+
<div class="container-fluid">
15+
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">ASPNETCoreMVCSerilog</a>
16+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
17+
aria-expanded="false" aria-label="Toggle navigation">
18+
<span class="navbar-toggler-icon"></span>
19+
</button>
20+
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
21+
<ul class="navbar-nav flex-grow-1">
22+
<li class="nav-item">
23+
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
24+
</li>
25+
<li class="nav-item">
26+
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
27+
</li>
28+
</ul>
29+
</div>
30+
</div>
31+
</nav>
32+
</header>
33+
<div class="container">
34+
<main role="main" class="pb-3">
35+
@RenderBody()
36+
</main>
37+
</div>
38+
39+
<footer class="border-top footer text-muted">
40+
<div class="container">
41+
&copy; 2022 - ASPNETCoreMVCSerilog - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
42+
</div>
43+
</footer>
44+
<script src="~/lib/jquery/dist/jquery.min.js"></script>
45+
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
46+
<script src="~/js/site.js" asp-append-version="true"></script>
47+
@await RenderSectionAsync("Scripts", required: false)
48+
</body>
49+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
a {
11+
color: #0077cc;
12+
}
13+
14+
.btn-primary {
15+
color: #fff;
16+
background-color: #1b6ec2;
17+
border-color: #1861ac;
18+
}
19+
20+
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
21+
color: #fff;
22+
background-color: #1b6ec2;
23+
border-color: #1861ac;
24+
}
25+
26+
.border-top {
27+
border-top: 1px solid #e5e5e5;
28+
}
29+
.border-bottom {
30+
border-bottom: 1px solid #e5e5e5;
31+
}
32+
33+
.box-shadow {
34+
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
35+
}
36+
37+
button.accept-policy {
38+
font-size: 1rem;
39+
line-height: inherit;
40+
}
41+
42+
.footer {
43+
position: absolute;
44+
bottom: 0;
45+
width: 100%;
46+
white-space: nowrap;
47+
line-height: 60px;
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
2+
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@using ASPNETCoreMVCSerilog
2+
@using ASPNETCoreMVCSerilog.Models
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@{
2+
Layout = "_Layout";
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)