Skip to content
Merged
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
3 changes: 2 additions & 1 deletion MBDEVproAPI.API/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
//global using Microsoft.OpenApi.Models;
global using Serilog;
global using Serilog.Formatting.Json;
global using Microsoft.OpenApi;
global using Microsoft.OpenApi;
global using Scalar.AspNetCore;

6 changes: 4 additions & 2 deletions MBDEVproAPI.API/MBDEVproAPI.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Scalar.AspNetCore" Version="2.12.40" />
<PackageReference Include="Scalar.AspNetCore" Version="2.13.1" />
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
<PackageReference Include="Serilog.Enrichers.Process" Version="3.0.0" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="4.0.0" />
<PackageReference Include="Serilog.Exceptions" Version="8.4.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="10.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="10.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.3" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.4" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.16.0" />
</ItemGroup>

Expand Down
54 changes: 42 additions & 12 deletions MBDEVproAPI.API/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
var builder = WebApplication.CreateBuilder(args);
var logger = new LoggerConfiguration()
.ReadFrom.Configuration(builder.Configuration)
.Enrich.FromLogContext()
.CreateLogger();
builder.Host.UseSerilog(logger);


using Scalar.AspNetCore;

var builder = WebApplication.CreateBuilder(args);

//DATABASE CONNECTION
builder.Services.AddDbContext<MBDEVproAPIDbContext>(options =>
Expand Down Expand Up @@ -45,11 +50,13 @@

var app = builder.Build();

app.UseSerilogRequestLogging();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi(); // Expose the OpenAPI JSON endpoint
app.MapScalarApiReference(); // Map the Scalar UI endpoint
//app.MapOpenApi(); // Expose the OpenAPI JSON endpoint
//app.MapScalarApiReference(); // Map the Scalar UI endpoint

Log.Information("MBDEVproAPI: (Development Environment)");
app.UseDeveloperExceptionPage();
Expand All @@ -72,16 +79,25 @@

if (app.Environment.IsDevelopment() || app.Environment.EnvironmentName == "Test")
{
app.UseSwagger();
app.UseSwaggerUI(c =>
{
//c.SwaggerEndpoint("/MBDEVproAPI/swagger/v1/swagger.json", "MBDEVproAPI v1 .NET CORE 10");
c.SwaggerEndpoint("../swagger/v1/swagger.json", "MBDEVproAPI v1 .NET CORE 10");
// ENDPOINTS: https://localhost:7092/swagger/index.html
// JSON: https://localhost:7092/swagger/v1/swagger.json
});
//app.UseSwagger();
//app.UseSwaggerUI(c =>
//{
// //c.SwaggerEndpoint("/MBDEVproAPI/swagger/v1/swagger.json", "MBDEVproAPI v1 .NET CORE 10");
// c.SwaggerEndpoint("../swagger/v1/swagger.json", "MBDEVproAPI v1 .NET CORE 10");
// // ENDPOINTS: https://localhost:7092/swagger/index.html
// // JSON: https://localhost:7092/swagger/v1/swagger.json
//});
}



//DEMO so can test with swagger and scalar UI, can remove later
app.MapOpenApi(); // Expose the OpenAPI JSON endpoint
app.MapScalarApiReference(); // Map the Scalar UI endpoint

Log.Information("MBDEVproAPI: (Development Environment)");
//app.UseDeveloperExceptionPage(); // For local only, can change later for testing and production environments, can also add custom error handling middleware for production environment.

app.MapScalarApiReference(options =>
{
options.Title = "MBDEVproAPI v1 .NET CORE 10";
Expand All @@ -90,11 +106,25 @@
});


//DEMO so can test with swagger and scalar UI, can remove later
app.UseSwagger();
app.UseSwaggerUI(c =>
{
//c.SwaggerEndpoint("/MBDEVproAPI/swagger/v1/swagger.json", "MBDEVproAPI v1 .NET CORE 10");
c.SwaggerEndpoint("../swagger/v1/swagger.json", "MBDEVproAPI v1 .NET CORE 10");
// ENDPOINTS: https://localhost:7092/swagger/index.html
// JSON: https://localhost:7092/swagger/v1/swagger.json
});

app.UseSerilogRequestLogging(); // Add Serilog request logging middleware

app.UseDeveloperExceptionPage(); // For local only, can change later for testing and production environments, can also add custom error handling middleware for production environment.

//Middleware
app.UseHttpsRedirection();

app.UseStaticFiles();

app.UseAuthorization();

app.MapControllers();
Expand Down
63 changes: 36 additions & 27 deletions MBDEVproAPI.API/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
{
"ConnectionStrings": {
//"DefaultConnection": "Server=ComputerPro7.local;Database=MBDEVproDB;Trusted_Connection=True;MultipleActiveResultSets=true",
// Use Secrets if passwords and so on...
"DefaultConnection": "Server=COMPUTERPRO7\\MSSQLSERVER2025;Initial Catalog=MBDEVproDB;Integrated Security=True;Encrypt=False;Trust Server Certificate=True"
"DefaultConnection": "Server=COMPUTERPRO7\\MSSQLSERVER2025;Initial Catalog=MBDEVproDB;Integrated Security=True;Encrypt=False;Trust Server Certificate=True"
},

"APISettings": {
//"APIUrl": "https://localhost:7092/api/Customer/",
//"AuthenticateUrl": "Account/Login",
//"ProjectID": "0",
//"BusinessID": "0",
//"IsUserExist": "Account/IsUserExist"

},

"DefaultProjectSettings": {
"ProjectName": "MBDEVproAPI",
"Description": "MBDEVproAPI version .NET CORE 10",
"DefaultFinishInspectionsStatus": "COMPLETED",
"SomeKey": "xcxc",
"SessionTimeout": "900000",
"ApplicationURL": "https://www.google.com",
"JSReport_TimeOutValue": "200000000",
Expand All @@ -35,26 +33,37 @@
"BaseUri": "https://localhost:7092/api/Customer/",
"ValidateTokenUri": "Auth/ValidateAppAccessToken"
},
"AllowedHosts": "*",
"Serilog": {
"Using": [ "Serilog.Exceptions" ],
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"Enrich": [ "FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId", "WithExceptionDetails" ],
"WriteTo": [
{
"Name": "ApplicationInsights",
"Args": {
"connectionString": "InstrumentationKey=xxxxx;IngestionEndpoint=https://MBDEVproAPI.applicationinsights.azure.com/;LiveEndpoint=https://MBDEVproAPI.livediagnostics.monitor.azure.com/;ApplicationId=xxxxx",
"telemetryConverter": "Serilog.Sinks.ApplicationInsights.TelemetryConverters.TraceTelemetryConverter, Serilog.Sinks.ApplicationInsights"
"HttpsRedirection": {
"Enabled": true,
"SSLPort": 443
},
"AllowedHosts": "*",
"Serilog": {
"Using": [ "Serilog.Exceptions" ],
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
}

]
}
}
},
"Enrich": [ "FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId", "WithExceptionDetails" ],
"WriteTo": [
{ "Name": "Console" },
{
"Name": "File",
"Args": {
"path": "X:\\Logs\\MBDEVpro\\MBDEVproAPI\\Development\\log.txt",
"outputTemplate": "{Timestamp:G} {Message}{NewLine:1}{Exception:1}"
}
},
{
"Name": "File",
"Args": {
"path": "X:\\Logs\\MBDEVpro\\MBDEVproAPI\\Development\\log.json",
"formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog"
}
}
]
}
}
4 changes: 4 additions & 0 deletions MBDEVproAPI.API/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
"Microsoft.AspNetCore": "Warning"
}
},
"HttpsRedirection": {
"Enabled": true,
"SSLPort": 443
},
"AllowedHosts": "*"
}
2 changes: 2 additions & 0 deletions MBDEVproAPI.BLL/MBDEVproAPI.BLL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<PackageReference Include="Serilog.Exceptions" Version="8.4.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="10.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="10.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down