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

Пшеничникова, Кузьмина, Дырда, Чевычелов #17

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
8 changes: 8 additions & 0 deletions .logs/log-20241201.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{"@t":"2024-12-01T14:02:49.9144101Z","@m":"Failed to determine the https port for redirect.","@i":"ca76cc21","@l":"Warning","@tr":"ffc049e44e3f1bdfa6d3bbf9eaea3602","@sp":"2ae0706c7ac125e3","EventId":{"Id":3,"Name":"FailedToDeterminePort"},"SourceContext":"Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware","RequestId":"0HN8I23BM6I9D:00000001","RequestPath":"/","ConnectionId":"0HN8I23BM6I9D","Environment":"Development"}
{"@t":"2024-12-01T14:02:50.0187580Z","@m":"Sample log. My name is \"vashe name\"","@i":"04820aad","@tr":"ffc049e44e3f1bdfa6d3bbf9eaea3602","@sp":"2ae0706c7ac125e3","MyName":"vashe name","SourceContext":"telemetry.Pages.IndexModel","ActionId":"de03b54a-3712-444b-9b1e-c7f822c68c36","ActionName":"/Index","RequestId":"0HN8I23BM6I9D:00000001","RequestPath":"/","ConnectionId":"0HN8I23BM6I9D","Environment":"Development"}
{"@t":"2024-12-01T14:02:50.1037174Z","@m":"HTTP \"GET\" \"/\" responded 200 in 118.9082 ms","@i":"62d0885c","@tr":"ffc049e44e3f1bdfa6d3bbf9eaea3602","@sp":"2ae0706c7ac125e3","RequestMethod":"GET","RequestPath":"/","StatusCode":200,"Elapsed":118.9082,"SourceContext":"Serilog.AspNetCore.RequestLoggingMiddleware","RequestId":"0HN8I23BM6I9D:00000001","ConnectionId":"0HN8I23BM6I9D","Environment":"Development"}
{"@t":"2024-12-01T14:02:59.5621578Z","@m":"Sample log. My name is \"vashe name\"","@i":"04820aad","@tr":"c064a28539a2b7abca3efef0845bad5e","@sp":"f135390a316b6395","MyName":"vashe name","SourceContext":"telemetry.Pages.IndexModel","ActionId":"de03b54a-3712-444b-9b1e-c7f822c68c36","ActionName":"/Index","RequestId":"0HN8I23BM6I9D:00000002","RequestPath":"/","ConnectionId":"0HN8I23BM6I9D","Environment":"Development"}
{"@t":"2024-12-01T14:02:59.5669133Z","@m":"HTTP \"GET\" \"/\" responded 200 in 5.1232 ms","@i":"62d0885c","@tr":"c064a28539a2b7abca3efef0845bad5e","@sp":"f135390a316b6395","RequestMethod":"GET","RequestPath":"/","StatusCode":200,"Elapsed":5.1232,"SourceContext":"Serilog.AspNetCore.RequestLoggingMiddleware","RequestId":"0HN8I23BM6I9D:00000002","ConnectionId":"0HN8I23BM6I9D","Environment":"Development"}
{"@t":"2024-12-01T14:03:00.4554363Z","@m":"HTTP \"GET\" \"/Privacy\" responded 200 in 5.2466 ms","@i":"62d0885c","@tr":"6612c07a7351dd13dd647ef3e2c75ba7","@sp":"4eea1f12572d85d4","RequestMethod":"GET","RequestPath":"/Privacy","StatusCode":200,"Elapsed":5.2466,"SourceContext":"Serilog.AspNetCore.RequestLoggingMiddleware","RequestId":"0HN8I23BM6I9D:00000003","ConnectionId":"0HN8I23BM6I9D","Environment":"Development"}
{"@t":"2024-12-01T14:03:04.1853687Z","@m":"Sample log. My name is \"vashe name\"","@i":"04820aad","@tr":"03a43c5df01351f20dd253d8894f01bf","@sp":"cc60151de469bb1b","MyName":"vashe name","SourceContext":"telemetry.Pages.IndexModel","ActionId":"de03b54a-3712-444b-9b1e-c7f822c68c36","ActionName":"/Index","RequestId":"0HN8I23BM6I9D:00000004","RequestPath":"/","ConnectionId":"0HN8I23BM6I9D","Environment":"Development"}
{"@t":"2024-12-01T14:03:04.1873547Z","@m":"HTTP \"GET\" \"/\" responded 200 in 2.1625 ms","@i":"62d0885c","@tr":"03a43c5df01351f20dd253d8894f01bf","@sp":"cc60151de469bb1b","RequestMethod":"GET","RequestPath":"/","StatusCode":200,"Elapsed":2.1625,"SourceContext":"Serilog.AspNetCore.RequestLoggingMiddleware","RequestId":"0HN8I23BM6I9D:00000004","ConnectionId":"0HN8I23BM6I9D","Environment":"Development"}
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 = "vashe name"; // ваше имя
_logger.LogInformation("Sample log. My name is {MyName}", myName);
}
}
83 changes: 60 additions & 23 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,62 @@
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorPages();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
using Elastic.Channels;
using Elastic.Ingest.Elasticsearch;
using Elastic.Ingest.Elasticsearch.DataStreams;
using Elastic.Serilog.Sinks;
using Elastic.Transport;
using Serilog;

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();
var builder = WebApplication.CreateBuilder(args);
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")); // Basic Auth
})
.Enrich.WithProperty("Environment", builder.Environment.EnvironmentName)
.ReadFrom.Configuration(builder.Configuration)
.CreateLogger();


builder.Host.UseSerilog();

builder.Services.AddSerilog(Log.Logger);
builder.Services.AddRazorPages();

var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
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();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseSerilogRequestLogging();
app.UseRouting();

app.UseAuthorization();

app.MapRazorPages();

app.Run();
}
catch (Exception ex)
{
Log.Logger.Error(ex.ToString());
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapRazorPages();

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.3" />
<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>