Skip to content

Commit 8c15c5f

Browse files
author
saikumar
committed
serilog_seq
1 parent ccc28db commit 8c15c5f

File tree

114 files changed

+52362
-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.

114 files changed

+52362
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page
2+
@model ErrorModel
3+
@{
4+
ViewData["Title"] = "Error";
5+
}
6+
7+
<h1 class="text-danger">Error.</h1>
8+
<h2 class="text-danger">An error occurred while processing your request.</h2>
9+
10+
@if (Model.ShowRequestId)
11+
{
12+
<p>
13+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
14+
</p>
15+
}
16+
17+
<h3>Development Mode</h3>
18+
<p>
19+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
20+
</p>
21+
<p>
22+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
23+
It can result in displaying sensitive information from exceptions to end users.
24+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
25+
and restarting the app.
26+
</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.AspNetCore.Mvc.RazorPages;
8+
using Microsoft.Extensions.Logging;
9+
10+
namespace serilogdemo.Pages
11+
{
12+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
13+
public class ErrorModel : PageModel
14+
{
15+
public string RequestId { get; set; }
16+
17+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
18+
19+
private readonly ILogger<ErrorModel> _logger;
20+
21+
public ErrorModel(ILogger<ErrorModel> logger)
22+
{
23+
_logger = logger;
24+
}
25+
26+
public void OnGet()
27+
{
28+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
29+
}
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@page
2+
@model IndexModel
3+
@{
4+
ViewData["Title"] = "Home page";
5+
}
6+
7+
<div class="text-center">
8+
<h1 class="display-4">Welcome</h1>
9+
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
10+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.AspNetCore.Mvc.RazorPages;
7+
using Microsoft.Extensions.Logging;
8+
9+
namespace serilogdemo.Pages
10+
{
11+
public class IndexModel : PageModel
12+
{
13+
private readonly ILogger<IndexModel> _logger;
14+
15+
public IndexModel(ILogger<IndexModel> logger)
16+
{
17+
_logger = logger;
18+
}
19+
20+
public void OnGet()
21+
{
22+
_logger.LogInformation("Your requested the index page");
23+
try
24+
{
25+
for (int i = 0; i < 100; i++)
26+
{
27+
if (i == 56)
28+
{
29+
throw new Exception("This is our demo exception");
30+
}
31+
else
32+
{
33+
_logger.LogInformation("The value of i is {iVariable}", i);
34+
}
35+
}
36+
}
37+
catch (Exception ex)
38+
{
39+
_logger.LogError(ex,"We caught exeception in the index get call");
40+
}
41+
}
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@page
2+
@model PrivacyModel
3+
@{
4+
ViewData["Title"] = "Privacy Policy";
5+
}
6+
<h1>@ViewData["Title"]</h1>
7+
8+
<p>Use this page to detail your site's privacy policy.</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.AspNetCore.Mvc.RazorPages;
7+
using Microsoft.Extensions.Logging;
8+
9+
namespace serilogdemo.Pages
10+
{
11+
public class PrivacyModel : PageModel
12+
{
13+
private readonly ILogger<PrivacyModel> _logger;
14+
15+
public PrivacyModel(ILogger<PrivacyModel> logger)
16+
{
17+
_logger = logger;
18+
}
19+
20+
public void OnGet()
21+
{
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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"] - serilogdemo</title>
7+
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
8+
<link rel="stylesheet" href="~/css/site.css" />
9+
</head>
10+
<body>
11+
<header>
12+
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
13+
<div class="container">
14+
<a class="navbar-brand" asp-area="" asp-page="/Index">serilogdemo</a>
15+
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
16+
aria-expanded="false" aria-label="Toggle navigation">
17+
<span class="navbar-toggler-icon"></span>
18+
</button>
19+
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
20+
<ul class="navbar-nav flex-grow-1">
21+
<li class="nav-item">
22+
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
23+
</li>
24+
<li class="nav-item">
25+
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
26+
</li>
27+
</ul>
28+
</div>
29+
</div>
30+
</nav>
31+
</header>
32+
<div class="container">
33+
<main role="main" class="pb-3">
34+
@RenderBody()
35+
</main>
36+
</div>
37+
38+
<footer class="border-top footer text-muted">
39+
<div class="container">
40+
&copy; 2019 - serilogdemo - <a asp-area="" asp-page="/Privacy">Privacy</a>
41+
</div>
42+
</footer>
43+
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+
48+
@RenderSection("Scripts", required: false)
49+
</body>
50+
</html>
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 serilogdemo
2+
@namespace serilogdemo.Pages
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@{
2+
Layout = "_Layout";
3+
}

serilogdemoapp/serilogdemo/Program.cs

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Hosting;
6+
using Microsoft.Extensions.Configuration;
7+
using Microsoft.Extensions.Hosting;
8+
using Microsoft.Extensions.Logging;
9+
using Serilog;
10+
11+
namespace serilogdemo
12+
{
13+
public class Program
14+
{
15+
public static void Main(string[] args)
16+
{
17+
var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
18+
Log.Logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
19+
try
20+
{
21+
Log.Information("Application Starting Up");
22+
CreateHostBuilder(args).Build().Run();
23+
}
24+
catch (Exception ex)
25+
{
26+
Log.Fatal(ex, "The application is failed to start correctly");
27+
throw;
28+
}
29+
finally
30+
{
31+
Log.CloseAndFlush();
32+
}
33+
}
34+
35+
public static IHostBuilder CreateHostBuilder(string[] args)
36+
{
37+
return Host.CreateDefaultBuilder(args).UseSerilog()
38+
.ConfigureWebHostDefaults(webBuilder =>
39+
{
40+
webBuilder.UseStartup<Startup>();
41+
});
42+
}
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:64847",
7+
"sslPort": 44332
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"serilogdemo": {
19+
"commandName": "Project",
20+
"launchBrowser": true,
21+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
22+
"environmentVariables": {
23+
"ASPNETCORE_ENVIRONMENT": "Development"
24+
}
25+
}
26+
}
27+
}

serilogdemoapp/serilogdemo/Startup.cs

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Builder;
6+
using Microsoft.AspNetCore.Hosting;
7+
using Microsoft.AspNetCore.HttpsPolicy;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.DependencyInjection;
10+
using Microsoft.Extensions.Hosting;
11+
using Serilog;
12+
13+
namespace serilogdemo
14+
{
15+
public class Startup
16+
{
17+
public Startup(IConfiguration configuration)
18+
{
19+
Configuration = configuration;
20+
}
21+
22+
public IConfiguration Configuration { get; }
23+
24+
// This method gets called by the runtime. Use this method to add services to the container.
25+
public void ConfigureServices(IServiceCollection services)
26+
{
27+
services.AddRazorPages();
28+
}
29+
30+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
31+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
32+
{
33+
if (env.IsDevelopment())
34+
{
35+
app.UseDeveloperExceptionPage();
36+
}
37+
else
38+
{
39+
app.UseExceptionHandler("/Error");
40+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
41+
app.UseHsts();
42+
}
43+
44+
app.UseHttpsRedirection();
45+
app.UseStaticFiles();
46+
47+
app.UseSerilogRequestLogging();
48+
49+
50+
app.UseRouting();
51+
52+
app.UseAuthorization();
53+
54+
app.UseEndpoints(endpoints =>
55+
{
56+
endpoints.MapRazorPages();
57+
});
58+
}
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Debug",
5+
"System": "Information",
6+
"Microsoft": "Information"
7+
}
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"AllowedHosts": "*",
3+
"Serilog": {
4+
"Using": [],
5+
"MininumLevel": {
6+
"Default": "Information",
7+
"Override": {
8+
"Microsoft": "Warning",
9+
"System": "Warning"
10+
}
11+
},
12+
"Enrich": [ "FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId" ],
13+
"WriteTo": [
14+
{ "Name": "Console" },
15+
{
16+
"Name": "File",
17+
"Args": {
18+
"path": "c:\\Demo\\Logs\\log.txt",
19+
"outputTemplate": "{Timestamp:G} {Message}{NewLine:1}{Exception:1}"
20+
}
21+
},
22+
{
23+
"Name": "File",
24+
"Args": {
25+
"path": "c:\\Demo\\Logs\\log.json",
26+
"formatter": "Serilog.Formatting.Json.JsonFormatter,Serilog"
27+
}
28+
},
29+
{
30+
"Name": "Seq",
31+
"Args": {
32+
"serverUrl": "http://localhost:8081"
33+
}
34+
}
35+
]
36+
}
37+
}
Binary file not shown.

0 commit comments

Comments
 (0)