Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ app.db
app.db-shm
app.db-wal
.mono
logs/

# Node.js dependencies
node_modules/
Expand Down
7 changes: 1 addition & 6 deletions src/RazorPagesProject/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ public async virtual Task AddMessageAsync(Message message)

public async virtual Task DeleteAllMessagesAsync()
{
foreach (var message in Messages)
{
Messages.Remove(message);
}

await SaveChangesAsync();
await Messages.ExecuteDeleteAsync();
}

public async virtual Task DeleteMessageAsync(int id)
Expand Down
15 changes: 14 additions & 1 deletion src/RazorPagesProject/Pages/GitHubProfile.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,20 @@ public async Task<IActionResult> OnGetAsync([FromRoute] string userName)
{
if (userName != null)
{
GitHubUser = await Client.GetUserAsync(userName);
try
{
GitHubUser = await Client.GetUserAsync(userName);
}
catch (HttpRequestException)
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HttpRequestExceptionの例外インスタンスをキャッチして、HTTP応答の詳細(ステータスコード、応答メッセージ)をロギングすべきです。これにより、GitHub APIの問題(レート制限、404エラーなど)のトラブルシューティングが容易になります。 / The HttpRequestException instance should be caught and logged with HTTP response details (status code, response message). This will facilitate troubleshooting of GitHub API issues (rate limits, 404 errors, etc.).

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d4d1fb8. Added logging with HTTP response details including status code: _logger.LogError(ex, "Failed to fetch GitHub profile for user '{UserName}'. Status: {StatusCode}", userName, ex.StatusCode)

{
ModelState.AddModelError(string.Empty, _localizer["ErrorFetchingProfile"]);
return Page();
}
catch (Exception)
{
ModelState.AddModelError(string.Empty, _localizer["UnexpectedError"]);
return Page();
}
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一般的なExceptionのキャッチは、例外の詳細情報をロギングすべきです。予期しないエラーのデバッグを容易にするため、ILoggerを注入してエラーの詳細をログに記録してください。 / The generic Exception catch should log the exception details. Inject ILogger and log the error details to facilitate debugging of unexpected errors.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d4d1fb8. Injected ILogger<GitHubProfileModel> into the constructor and added error logging: _logger.LogError(ex, "Unexpected error occurred while fetching GitHub profile for user '{UserName}'", userName)

}

return Page();
Expand Down
16 changes: 13 additions & 3 deletions src/RazorPagesProject/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
using RazorPagesProject.Data;
using RazorPagesProject.Services;
using System.Globalization;
using Serilog;

var builder = WebApplication.CreateBuilder(args);

builder.Host.UseSerilog((context, services, configuration) => configuration
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.File("logs/app-.txt", rollingInterval: RollingInterval.Day));
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ファイルパスのプレースホルダーが不完全です。"logs/app-.txt""logs/app-{Date}.txt"にすべきです({Date}プレースホルダーを追加)。現在の設定では、Serilogは日付をファイル名に正しく挿入できません。 / The file path placeholder is incomplete. "logs/app-.txt" should be "logs/app-{Date}.txt" (add {Date} placeholder). With the current configuration, Serilog cannot correctly insert the date into the filename.

Suggested change
.WriteTo.File("logs/app-.txt", rollingInterval: RollingInterval.Day));
.WriteTo.File("logs/app-{Date}.txt", rollingInterval: RollingInterval.Day));

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d4d1fb8. Changed the file path from "logs/app-.txt" to "logs/app-{Date}.txt" to include the date placeholder for proper daily rolling.



// Add services to the container.
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseSqlite(connectionString));
Expand Down Expand Up @@ -44,7 +53,8 @@
{
client.BaseAddress = new Uri("https://api.github.com");
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Yolo", "0.1.0"));
});
})
.AddStandardResilienceHandler();

builder.Services.AddScoped<IQuoteService, QuoteService>();

Expand All @@ -60,11 +70,11 @@
else
{
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.UseHttpsRedirection();

app.UseStaticFiles();

app.UseRequestLocalization();
Expand Down
6 changes: 3 additions & 3 deletions src/RazorPagesProject/RazorPagesProject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="10.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
</ItemGroup>

<!-- The following target is a workaround for https://github.com/dotnet/aspnetcore/issues/59625 -->
<Target
Name="Workaround_ResolveBuildCompressedStaticWebAssetsConfiguration"
BeforeTargets="ResolveBuildCompressedStaticWebAssetsConfiguration">
<Target Name="Workaround_ResolveBuildCompressedStaticWebAssetsConfiguration" BeforeTargets="ResolveBuildCompressedStaticWebAssetsConfiguration">
<!-- Remove any duplicate items from StaticWebAssets -->

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/RazorPagesProject/Resources/Pages/GitHubProfile.en.resx
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,10 @@
<data name="Language" xml:space="preserve">
<value>Language</value>
</data>
<data name="ErrorFetchingProfile" xml:space="preserve">
<value>Unable to fetch the GitHub profile. Please check the username and try again.</value>
</data>
<data name="UnexpectedError" xml:space="preserve">
<value>An unexpected error occurred. Please try again later.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/RazorPagesProject/Resources/Pages/GitHubProfile.ja.resx
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,10 @@
<data name="Language" xml:space="preserve">
<value>言語</value>
</data>
<data name="ErrorFetchingProfile" xml:space="preserve">
<value>GitHubプロフィールを取得できませんでした。ユーザー名を確認して、もう一度お試しください。</value>
</data>
<data name="UnexpectedError" xml:space="preserve">
<value>予期しないエラーが発生しました。後でもう一度お試しください。</value>
</data>
</root>
Loading