Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Logs #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions BioMed.Api/BioMed.Api/Extensions/ConfigureServicesExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using BioMed.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
using Serilog;

namespace BioMed.Api.Extensions
{
Expand All @@ -14,5 +15,16 @@ public static IServiceCollection ConfigureDatabaseContext(this IServiceCollectio

return services;
}
public static IServiceCollection ConfigureLogger(this IServiceCollection services)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.WriteTo.Console()
.WriteTo.File("logs/logs.txt", rollingInterval: RollingInterval.Day)
.WriteTo.File("logs/error_.txt", Serilog.Events.LogEventLevel.Error, rollingInterval: RollingInterval.Day)
.CreateLogger();

return services;
}
}
}
4 changes: 4 additions & 0 deletions BioMed.Api/BioMed.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
using System.Text;
using Serilog;

namespace BioMed.Api
{
Expand All @@ -12,12 +13,15 @@ public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);

builder.Host.UseSerilog();

builder.Services.AddControllers()
.AddNewtonsoftJson()
.AddXmlSerializerFormatters();

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.ConfigureLogger();
builder.Services.ConfigureDatabaseContext();
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
builder.Services.AddAuthentication("Bearer")
Expand Down
2 changes: 1 addition & 1 deletion BioMed.Api/BioMed.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
},
"ConnectionStrings": {
"BioMedConnection": "Data Source=DESKTOP-DH82C7P;Initial Catalog=BioMed;Integrated Security=True;Trust Server Certificate=True"
"BioMedConnection": "Data Source=LAPTOP-TEN57IC2\\MSSQLSERVER01;Initial Catalog=BioMed;Integrated Security=True;Trust Server Certificate=True"
},
"AllowedHosts": "*"
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

#nullable disable

namespace BioMed.Infrastructure.Persistence.Migrations
namespace BioMed.Infrastructure.persistence.Migrations
{
/// <inheritdoc />
public partial class Initial_Create : Migration
public partial class initial_create : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#nullable disable

namespace BioMed.Infrastructure.Persistence.Migrations
namespace BioMed.Infrastructure.persistence.Migrations
{
[DbContext(typeof(BioMedDbContext))]
partial class BioMedDbContextModelSnapshot : ModelSnapshot
Expand Down
3 changes: 2 additions & 1 deletion BioMed.Api/BioMed.Services/Services/DiseaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class DiseaseService : IDiseaseService
private readonly IMapper _mapper;
private readonly BioMedDbContext _context;

public DiseaseService(IMapper mapper, BioMedDbContext context)
public DiseaseService(IMapper mapper,
BioMedDbContext context)
{
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
_context = context ?? throw new ArgumentNullException(nameof(context));
Expand Down
3 changes: 2 additions & 1 deletion BioMed.Api/BioMed.Services/Services/PaymentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class PaymentService : IPaymentService
private readonly IMapper _mapper;
private readonly BioMedDbContext _context;

public PaymentService(IMapper mapper, BioMedDbContext context)
public PaymentService(IMapper mapper,
BioMedDbContext context)
{
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
_context = context ?? throw new ArgumentNullException(nameof(context));
Expand Down
3 changes: 2 additions & 1 deletion BioMed.Api/BioMed.Services/Services/TreatmentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class TreatmentService : ITreatmentService
private readonly IMapper _mapper;
private readonly BioMedDbContext _context;

public TreatmentService(IMapper mapper, BioMedDbContext context)
public TreatmentService(IMapper mapper,
BioMedDbContext context)
{
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
_context = context ?? throw new ArgumentNullException(nameof(context));
Expand Down