Ajout des logs
continuous-integration/drone/push Build is passing Details

blazor
Antoine JOURDAIN 1 year ago
parent 7652373f09
commit 220be1c9cd

@ -13,6 +13,7 @@ using Microsoft.Extensions.Options;
using Microsoft.Net.Http.Headers;
using adminBlazor.Models;
using adminBlazor;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Components.Authorization;
@ -29,8 +30,6 @@ builder.Services.AddRazorPages();
builder.Services.AddScoped<IDataService, DataApiService>();
builder.Services.AddScoped<IDataService, DataLocalService>();
builder.Services.AddScoped<IVocListService, VocListLocalService>();
builder.Services.AddOptions();
@ -51,7 +50,7 @@ builder.Services.AddControllers();
// Add the localization to the app and specify the resources path
builder.Services.AddLocalization(opts => { opts.ResourcesPath = "Resources"; });
// Configure the localtization
// Configure the localization
builder.Services.Configure<RequestLocalizationOptions>(options =>
{
// Set the default culture of the web site
@ -62,13 +61,14 @@ builder.Services.AddControllers();
options.SupportedUICultures = new List<CultureInfo> { new CultureInfo("en-US"), new CultureInfo("fr-FR") };
});
builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging"));
builder.Services
.AddBlazorise()
.AddBootstrapProviders()
.AddFontAwesomeIcons();
var app = builder.Build();
// Configure the HTTP request pipeline.
@ -104,4 +104,3 @@ builder.Services.AddControllers();
app.MapFallbackToPage("/_Host");
app.Run();

@ -9,6 +9,12 @@
public class AuthService : IAuthService
{
private static readonly List<AppUser> CurrentUser;
private readonly ILogger<AuthService> _logger;
public AuthService(ILogger<AuthService> logger)
{
_logger = logger;
}
static AuthService()
{
@ -25,6 +31,7 @@
if (user == null)
{
_logger.LogWarning("Authentication failed, field invalid.");
throw new Exception("User name or password invalid !");
}
@ -45,13 +52,17 @@
if (user == null)
{
_logger.LogWarning("Authentication : login failed, field invalid.");
throw new Exception("User name or password invalid !");
}
_logger.LogInformation("Authentication : login success.");
}
public void Register(RegisterRequest registerRequest)
{
CurrentUser.Add(new AppUser { UserName = registerRequest.UserName, Password = registerRequest.Password, Roles = new List<string> { "guest" } });
_logger.LogInformation("Authentication : register success.");
}
}
}

@ -8,11 +8,14 @@ namespace adminBlazor.Services
public class DataApiService : IDataService
{
private readonly HttpClient _http;
private readonly ILogger<DataApiService> _logger;
public DataApiService(
HttpClient http)
HttpClient http,
ILogger<DataApiService> logger)
{
_http = http;
_logger = logger;
}
public async Task Add(UserModel model)
@ -22,6 +25,8 @@ namespace adminBlazor.Services
// Save the data
await _http.PostAsJsonAsync("https://localhost:7234/api/User/", item);
_logger.LogInformation("User API : call of method ADD. Creation of user ID : {Id}.", item.Id);
}
public async Task<int> Count()
@ -31,11 +36,13 @@ namespace adminBlazor.Services
public async Task<List<User>> List(int currentPage, int pageSize)
{
_logger.LogInformation("User API : call of method LIST.");
return await _http.GetFromJsonAsync<List<User>>($"https://localhost:7234/api/User/?currentPage={currentPage}&pageSize={pageSize}");
}
public async Task<User> GetById(int id)
{
_logger.LogInformation("User API : call of method GetByID.");
return await _http.GetFromJsonAsync<User>($"https://localhost:7234/api/User/{id}");
}
@ -44,11 +51,14 @@ namespace adminBlazor.Services
// Get the item
var item = UserFactory.Create(model);
_logger.LogInformation("User API : call of method UPDATE on User ID : {Id}.", id);
await _http.PutAsJsonAsync($"https://localhost:7234/api/User/{id}", item);
}
public async Task Delete(int id)
{
_logger.LogInformation("User API : call of method DELETE on User ID : {Id}.", id);
await _http.DeleteAsync($"https://localhost:7234/api/User/{id}");
}

@ -8,9 +8,20 @@
]
},
"Logging": {
"LogLevel": {
"Default": "Error",
"Microsoft": "Warning"
},
"Debug": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Microsoft.Hosting": "Trace"
}
},
"EventSource": {
"LogLevel": {
"Default": "Warning"
}
}
},
"AllowedHosts": "*"

Loading…
Cancel
Save