soat-fiap / FIAP.TechChallenge.ByteMeBurger

Repository for FIAP SOAT post degree Tech Challenge
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Add logs #31

Closed italopessoa closed 1 month ago

italopessoa commented 2 months ago

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like A clear and concise description of what you want to happen.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

coderabbitai[bot] commented 2 months ago

Configuring Serilog for Logging

To enhance the logging capabilities of your .NET application using Serilog, follow these steps:

  1. Install Serilog Packages: Run the following command in your project directory:

    dotnet add package Serilog.AspNetCore
  2. Configure Serilog in Program.cs: Add the following code to your Program.cs to set up Serilog:

    using Serilog;
    
    var builder = WebApplication.CreateBuilder(args);
    
    // Configure Serilog
    builder.Host.UseSerilog((context, config) =>
    {
       config.ReadFrom.Configuration(context.Configuration);
    });
    
    var app = builder.Build();
  3. Example Usage in ProductController: Here's how you can use Serilog to log an error in the ProductController:

    catch (Exception e)
    {
       _logger.LogError(e, "Unable to create the product.");
       return BadRequest("Unable to create the product.");
    }

These steps will set up basic logging in your application. For more advanced configurations, refer to the Serilog documentation.