Premiers affichages de log effectués

develop
Yanaël GRETTE 4 years ago
parent 81c5b3043f
commit d673d32cb3
  1. 15
      Controllers/CollaborateursApi.cs
  2. 1
      EPAServeur.csproj
  3. 4
      Program.cs
  4. 2
      Properties/launchSettings.json
  5. 11
      Startup.cs

@ -19,6 +19,7 @@ using IO.Swagger.Security;
using Microsoft.AspNetCore.Authorization;
using IO.Swagger.DTO;
using EPAServeur.IServices;
using Microsoft.Extensions.Logging;
namespace IO.Swagger.Controllers
{
@ -29,9 +30,11 @@ namespace IO.Swagger.Controllers
public class CollaborateursApiController : ControllerBase
{
private readonly ICollaborateurService collaborateurService;
public CollaborateursApiController(ICollaborateurService _collaborateurService)
private readonly ILogger<CollaborateursApiController> logger;
public CollaborateursApiController(ICollaborateurService _collaborateurService, ILogger<CollaborateursApiController> _logger)
{
collaborateurService = _collaborateurService;
logger = _logger;
}
/// <summary>
///
@ -53,10 +56,11 @@ namespace IO.Swagger.Controllers
{
//TODO: Uncomment the next line to return response 403 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(403, default(ErreurDTO));
logger.LogInformation("Récupération du collaborateur d'ID {idCollaborateur}", idCollaborateur);
CollaborateurDTO collaborateurDTO = collaborateurService.GetCollaborateurById(idCollaborateur);
if( collaborateurDTO == null)
{
logger.LogWarning("Le ccollaborateur {id} est introuvable", idCollaborateur);
ErreurDTO erreurDTO = new ErreurDTO()
{
Code = "404",
@ -64,6 +68,7 @@ namespace IO.Swagger.Controllers
};
return NotFound(erreurDTO);
}
logger.LogInformation("Collaborateur {id} trouvée", idCollaborateur);
return Ok(collaborateurDTO);
}
@ -87,10 +92,11 @@ namespace IO.Swagger.Controllers
{
//TODO: Uncomment the next line to return response 403 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(403, default(ErreurDTO));
logger.LogInformation("Récupération d'un collaborateur par le mail {mail}", mail);
CollaborateurDTO collaborateurDTO = collaborateurService.GetCollaborateurByMail(mail);
if (collaborateurDTO == null)
{
logger.LogWarning("Le collaborateur {mail} est introuvable", mail);
ErreurDTO erreurDTO = new ErreurDTO()
{
Code = "404",
@ -98,6 +104,7 @@ namespace IO.Swagger.Controllers
};
return NotFound(erreurDTO);
}
logger.LogInformation("Collaborateur {mail} trouvée", mail);
return Ok(collaborateurDTO);
}
@ -127,7 +134,7 @@ namespace IO.Swagger.Controllers
{
//TODO: Uncomment the next line to return response 403 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(403, default(ErreurDTO));
logger.LogInformation("Récupération de la liste des collaborateurs");
return Ok(collaborateurService.GetCollaborateurs(asc, numPage, parPAge, fonctions, idAgence, idBU, texte, tri));
}

@ -10,6 +10,7 @@
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.21" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="RestSharp" Version="106.11.4" />
<PackageReference Include="Serilog.Extensions.Logging.File" Version="2.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.5.1" />

@ -21,6 +21,10 @@ namespace EPAServeur
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureLogging(logging =>
{
logging.ClearProviders();
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();

@ -12,7 +12,7 @@
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/notes/1",
"launchUrl": "api/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}

@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using EPAServeur.Context;
using EPAServeur.IServices;
using EPAServeur.Services;
@ -10,12 +6,11 @@ using IO.Swagger.Security;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.IO;
namespace EPAServeur
{
@ -62,8 +57,10 @@ namespace EPAServeur
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory logger)
{
string path = Directory.GetCurrentDirectory();
logger.AddFile(path+"Log/loggerfile-{Date}.txt");
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();

Loading…
Cancel
Save