diff --git a/Controllers/CollaborateursApi.cs b/Controllers/CollaborateursApi.cs index ead8209..3bfc315 100644 --- a/Controllers/CollaborateursApi.cs +++ b/Controllers/CollaborateursApi.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 logger; + public CollaborateursApiController(ICollaborateurService _collaborateurService, ILogger _logger) { collaborateurService = _collaborateurService; + logger = _logger; } /// /// @@ -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); } @@ -124,10 +131,10 @@ namespace IO.Swagger.Controllers [SwaggerResponse(statusCode: 200, type: typeof(List), description: "OK")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] public virtual IActionResult GetCollaborateurs([FromQuery][Required()]bool? asc, [FromQuery][Required()]int? numPage, [FromQuery][Required()]int? parPAge, [FromQuery]List fonctions, [FromQuery]long? idAgence, [FromQuery]long? idBU, [FromQuery]string texte, [FromQuery]string tri) - { + { //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)); } diff --git a/EPAServeur.csproj b/EPAServeur.csproj index c4915ce..5900bca 100644 --- a/EPAServeur.csproj +++ b/EPAServeur.csproj @@ -10,6 +10,7 @@ + diff --git a/Program.cs b/Program.cs index dda309a..6ec487d 100644 --- a/Program.cs +++ b/Program.cs @@ -21,6 +21,10 @@ namespace EPAServeur public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) + .ConfigureLogging(logging => + { + logging.ClearProviders(); + }) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json index 9790dad..0c92275 100644 --- a/Properties/launchSettings.json +++ b/Properties/launchSettings.json @@ -12,7 +12,7 @@ "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, - "launchUrl": "api/notes/1", + "launchUrl": "api/", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/Startup.cs b/Startup.cs index 7290f43..9ce6936 100644 --- a/Startup.cs +++ b/Startup.cs @@ -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();