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;
@ -22,15 +23,13 @@ var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddSingleton<WeatherForecastService>();
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddSingleton<WeatherForecastService>();
builder.Services.AddScoped<IDataService, DataApiService>();
builder.Services.AddScoped<IDataService, DataLocalService>();
builder.Services.AddScoped<IVocListService, VocListLocalService>();
builder.Services.AddOptions();
@ -41,67 +40,67 @@ builder.Services.AddScoped<IAuthService, AuthService>();
builder.Services.AddHttpClient();
builder.Services.AddBlazoredLocalStorage();
builder.Services.AddBlazoredModal();
builder.Services.AddBlazoredLocalStorage();
builder.Services.AddBlazoredModal();
// Add the controller of the app
builder.Services.AddControllers();
// Add the localization to the app and specify the resources path
builder.Services.AddLocalization(opts => { opts.ResourcesPath = "Resources"; });
// Configure the localtization
builder.Services.Configure<RequestLocalizationOptions>(options =>
{
// Set the default culture of the web site
options.DefaultRequestCulture = new RequestCulture(new CultureInfo("en-US"));
// Declare the supported culture
options.SupportedCultures = new List<CultureInfo> { new CultureInfo("en-US"), new CultureInfo("fr-FR") };
options.SupportedUICultures = new List<CultureInfo> { new CultureInfo("en-US"), new CultureInfo("fr-FR") };
});
builder.Services
.AddBlazorise()
.AddBootstrapProviders()
.AddFontAwesomeIcons();
var app = builder.Build();
// Configure the HTTP request pipeline.
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.UseRouting();
// Get the current localization options
var options = ((IApplicationBuilder)app).ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>();
if (options?.Value != null)
{
// use the default localization
app.UseRequestLocalization(options.Value);
}
// Add the localization to the app and specify the resources path
builder.Services.AddLocalization(opts => { opts.ResourcesPath = "Resources"; });
// Configure the localization
builder.Services.Configure<RequestLocalizationOptions>(options =>
{
// Set the default culture of the web site
options.DefaultRequestCulture = new RequestCulture(new CultureInfo("en-US"));
// Declare the supported culture
options.SupportedCultures = new List<CultureInfo> { new CultureInfo("en-US"), new CultureInfo("fr-FR") };
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.
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.UseRouting();
// Get the current localization options
var options = ((IApplicationBuilder)app).ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>();
if (options?.Value != null)
{
// use the default localization
app.UseRequestLocalization(options.Value);
}
// Add the controller to the endpoint
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.Run();
app.MapBlazorHub();
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,12 +36,14 @@ 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)
{
return await _http.GetFromJsonAsync<User>($"https://localhost:7234/api/User/{id}");
_logger.LogInformation("User API : call of method GetByID.");
return await _http.GetFromJsonAsync<User>($"https://localhost:7234/api/User/{id}");
}
public async Task Update(int id, UserModel model)
@ -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": "Information",
"Microsoft.AspNetCore": "Warning"
"LogLevel": {
"Default": "Error",
"Microsoft": "Warning"
},
"Debug": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting": "Trace"
}
},
"EventSource": {
"LogLevel": {
"Default": "Warning"
}
}
},
"AllowedHosts": "*"

Loading…
Cancel
Save