Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Бойко, Москалев, Федоров, Щеглеватов #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .logs/log-20241126.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{"@t":"2024-11-26T10:07:33.7349640Z","@m":"Failed to determine the https port for redirect.","@i":"ca76cc21","@l":"Warning","@tr":"aec78447a82b7da9f6912bb6ce17acfc","@sp":"38ed0dbf01f5db46","EventId":{"Id":3,"Name":"FailedToDeterminePort"},"SourceContext":"Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware","RequestId":"0HN8E08IIDI6D:00000001","RequestPath":"/","ConnectionId":"0HN8E08IIDI6D"}
{"@t":"2024-11-26T10:07:34.0467650Z","@m":"HTTP \"GET\" \"/\" responded 200 in 212.9951 ms","@i":"62d0885c","@tr":"aec78447a82b7da9f6912bb6ce17acfc","@sp":"38ed0dbf01f5db46","RequestMethod":"GET","RequestPath":"/","StatusCode":200,"Elapsed":212.9951,"SourceContext":"Serilog.AspNetCore.RequestLoggingMiddleware"}
{"@t":"2024-11-26T10:46:21.7330327Z","@m":"Failed to determine the https port for redirect.","@i":"ca76cc21","@l":"Warning","@tr":"8d110a3dced651ef26b0412103bcd7ae","@sp":"b2bc37737efc6569","EventId":{"Id":3,"Name":"FailedToDeterminePort"},"SourceContext":"Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware","RequestId":"0HN8E0U8FV9J9:00000001","RequestPath":"/","ConnectionId":"0HN8E0U8FV9J9"}
{"@t":"2024-11-26T10:46:21.9820781Z","@m":"HTTP \"GET\" \"/\" responded 200 in 170.0960 ms","@i":"62d0885c","@tr":"8d110a3dced651ef26b0412103bcd7ae","@sp":"b2bc37737efc6569","RequestMethod":"GET","RequestPath":"/","StatusCode":200,"Elapsed":170.096,"SourceContext":"Serilog.AspNetCore.RequestLoggingMiddleware"}
{"@t":"2024-11-26T10:57:18.7609691Z","@m":"Failed to determine the https port for redirect.","@i":"ca76cc21","@l":"Warning","@tr":"71b8f3d6027173bac22482a73b45b105","@sp":"9d13b408b57fb4a1","EventId":{"Id":3,"Name":"FailedToDeterminePort"},"SourceContext":"Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware","RequestId":"0HN8E14C7E31N:00000001","RequestPath":"/","ConnectionId":"0HN8E14C7E31N"}
{"@t":"2024-11-26T10:57:18.9092093Z","@m":"Sample log. My name is \"Vladimir\"","@i":"04820aad","@tr":"71b8f3d6027173bac22482a73b45b105","@sp":"9d13b408b57fb4a1","MyName":"Vladimir","SourceContext":"telemetry.Pages.IndexModel","ActionId":"9ed1f574-d53d-44fd-b574-1c5ab9b42994","ActionName":"/Index","RequestId":"0HN8E14C7E31N:00000001","RequestPath":"/","ConnectionId":"0HN8E14C7E31N"}
{"@t":"2024-11-26T10:57:19.0484215Z","@m":"HTTP \"GET\" \"/\" responded 200 in 194.3876 ms","@i":"62d0885c","@tr":"71b8f3d6027173bac22482a73b45b105","@sp":"9d13b408b57fb4a1","RequestMethod":"GET","RequestPath":"/","StatusCode":200,"Elapsed":194.3876,"SourceContext":"Serilog.AspNetCore.RequestLoggingMiddleware"}
1 change: 1 addition & 0 deletions Pages/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>

3 changes: 2 additions & 1 deletion Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public IndexModel(ILogger<IndexModel> logger)

public void OnGet()
{

var myName = "Vladimir";
_logger.LogInformation("Sample log. My name is {MyName}", myName);
}
}
71 changes: 55 additions & 16 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,64 @@
var builder = WebApplication.CreateBuilder(args);
using Elastic.Channels;
using Elastic.Ingest.Elasticsearch;
using Elastic.Ingest.Elasticsearch.DataStreams;
using Elastic.Serilog.Sinks;
using Elastic.Transport;
using Serilog;

// Add services to the container.
builder.Services.AddRazorPages();
var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.Elasticsearch(new []{ new Uri("http://localhost:9200") }, opts =>
{
opts.DataStream = new DataStreamName("logs", "telemetry-logging", "demo");
opts.BootstrapMethod = BootstrapMethod.Failure;
opts.ConfigureChannel = channelOpts =>
{
channelOpts.BufferOptions = new BufferOptions
{
ExportMaxConcurrency = 10
};
};
}, transport =>
{
transport.Authentication(new BasicAuthentication("elastic", "changeme"));
})
.Enrich.WithProperty("Environment", builder.Environment.EnvironmentName)
.ReadFrom.Configuration(builder.Configuration)
.CreateLogger();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
try
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
builder.Services.AddRazorPages();

builder.Host.UseSerilog();

builder.Services.AddSerilog((hostingContext, loggerConfiguration) =>
loggerConfiguration.ReadFrom.Configuration(hostingContext.GetService<HostBuilderContext>().Configuration));

app.UseHttpsRedirection();
app.UseStaticFiles();
var app = builder.Build();

app.UseRouting();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}

app.UseAuthorization();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSerilogRequestLogging();

app.MapRazorPages();
app.UseRouting();

app.UseAuthorization();

app.MapRazorPages();

app.Run();
}
catch (Exception e)
{
Log.Logger.Fatal($"Fatal: {e.Message}");
}

app.Run();
10 changes: 1 addition & 9 deletions appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
{
"DetailedErrors": true,
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
{}
26 changes: 23 additions & 3 deletions appsettings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
{
"Logging": {
"LogLevel": {
"Serilog": {
"WriteTo": [
{
"Name": "File",
"Args": {
"path": ".logs/log-.txt",
"formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact",
"rollingInterval": "Day",
"rollOnFileSizeLimit": true
}
},
{
"Name": "Console",
"Args": {
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} {Properties:j}{NewLine}{Exception}"
}
}
],
"MinimumLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
}
},
"AllowedHosts": "*"
Expand Down
7 changes: 7 additions & 0 deletions telemetry.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Elastic.Serilog.Sinks" Version="8.12.2" />
<PackageReference Include="Serilog" Version="4.1.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
</ItemGroup>

</Project>