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

Update nugets versions and serilog settings #8

Merged
merged 4 commits into from
Apr 15, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ public async Task<OperationResult<UserProfileViewModel>> RegisterAsync(RegisterV
operation.AddSuccess(AppData.Messages.UserSuccessfullyRegistered);
_logger.LogInformation(operation.GetMetadataMessages());
await transaction.CommitAsync(cancellationToken);
_logger.MicroserviceUserRegistration(model.Email);
_logger.LogInformation("User {@User} successfully created with {@Role}", model, role);
return await Task.FromResult(operation);
}
}
var errors = result.Errors.Select(x => $"{x.Code}: {x.Description}");
operation.AddError(string.Join(", ", errors));
operation.Exception = _unitOfWork.LastSaveChangesResult.Exception;
await transaction.RollbackAsync(cancellationToken);
_logger.MicroserviceUserRegistration(model.Email, operation.Exception);
_logger.LogError(operation.Exception, "User {@User} creation failed", model);
return await Task.FromResult(operation);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentValidation;
using Calabonga.OperationResults;
using FluentValidation;
using MediatR;

namespace Calabonga.Microservice.IdentityModule.Web.Application;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@

<ItemGroup>
<PackageReference Include="Automapper" Version="12.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="Calabonga.AspNetCore.AppDefinitions" Version="1.2.2" />
<PackageReference Include="FluentValidation" Version="11.5.1" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.5.1" />
<PackageReference Include="FluentValidation" Version="11.5.2" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.5.2" />
<PackageReference Include="MediatR" Version="12.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3">
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="OpenIddict.AspNetCore" Version="4.1.0" />

<PackageReference Include="OpenIddict.AspNetCore" Version="4.2.0" />
<PackageReference Include="Serilog.AspNetCore" Version="6.1.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,15 @@ public async Task<OperationResult<EventItemViewModel>> Handle(PostEventItemReque
var lastResult = _unitOfWork.LastSaveChangesResult;
if (lastResult.IsOk)
{

var mapped = _mapper.Map<EventItem, EventItemViewModel>(entity);

operation.Result = mapped;
operation.AddSuccess("Successfully created");
_logger.LogInformation("EventItem {@EventItem} successfully created", entity);
return operation;
}

operation.AddError(lastResult.Exception ?? new ApplicationException("Something went wrong"));

return operation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ public record GetRolesRequest : IRequest<string>;
public class GetRolesRequestHandler : IRequestHandler<GetRolesRequest, string>
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ILogger<GetRolesRequestHandler> _logger;

public GetRolesRequestHandler(IHttpContextAccessor httpContextAccessor) => _httpContextAccessor = httpContextAccessor;
public GetRolesRequestHandler(IHttpContextAccessor httpContextAccessor, ILogger<GetRolesRequestHandler> logger)
{
_httpContextAccessor = httpContextAccessor;
_logger = logger;
}

public Task<string> Handle(GetRolesRequest request, CancellationToken cancellationToken)
{
var user = _httpContextAccessor.HttpContext!.User;
var roles = ClaimsHelper.GetValues<string>((ClaimsIdentity)user.Identity!, "role");
_logger.LogInformation("Current user {@UserName} have following roles {@Roles}", user.Identity.Name, roles);
return Task.FromResult($"Current user ({user.Identity!.Name}) have following roles: {string.Join("|", roles)}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@
Сервер авторизации
</h1>
<p class="small text-center text-muted">
Version: 7.0.3
Version: 7.0.4
</p>
</div>
</div>
<div class="row">
@RenderBody()

</div>
<div class="row mt-5">
<div class="col">
<p class="small text-center text-muted">
<a href="https://www.calabonga.net/blog/all/index/1?tag=nimble">Nimble Framework</a> 2023 &copy; Calabonga SOFT
<a class="text-decoration-none text-muted" href="https://www.calabonga.net/blog/all/index/1?tag=nimble">Nimble Framework</a> 2023 &copy; Calabonga SOFT
</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Name: Template for Micro service on ASP.NET Core API with
// OpenIddict (OAuth2.0)
// Author: Calabonga © 2005-2023 Calabonga SOFT
// Version: 7.0.3
// Version: 7.0.4
// Based on: .NET 7.0.x
// Created Date: 2022-11-12 09:29
// Updated Date: 2023-03-11 13:25
// Updated Date: 2023-04-15 08:17
// --------------------------------------------------------------------
// Contacts
// --------------------------------------------------------------------
Expand Down Expand Up @@ -38,7 +38,8 @@

// created builder
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog();
builder.Host.UseSerilog((context, configuration) =>
configuration.ReadFrom.Configuration(context.Configuration));

// adding definitions for application
builder.Services.AddDefinitions(builder, typeof(Program));
Expand All @@ -49,6 +50,9 @@
// using definition for application
app.UseDefinitions();

// using Serilog request logging
app.UseSerilogRequestLogging();

// start application
app.Run();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
{
"Cors": {
"Origins": "*"
"Cors": {
"Origins": "*"
},
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Warning",
"System": "Warning",
"OpenIddict": "Warning"
}
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"WriteTo": [
{ "Name": "Console" },
{
"Name": "File",
"Args": {
"path": "/logs/log-.log",
"rollingInterval": "Day",
"rollOnFileSizeLimit": true,
"shared": true,
"formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact"
}
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
{
"ConnectionStrings": {
"ApplicationDbContext": "Server=<SQL>;Database=<DatabaseName>;User ID=<UserName>;Password=<Password>"
"ConnectionStrings": {
"ApplicationDbContext": "Server=<SQL>;Database=<DatabaseName>;User ID=<UserName>;Password=<Password>"
},
"Serilog": {
"Using": [ "Serilog.Sinks.Console" ],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AuthServer": {
"Url": "https://localhost:10001"
},
"AllowedHosts": "*"
"WriteTo": [
{ "Name": "Console" }
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
},
"AuthServer": {
"Url": "https://localhost:10001"
},
"AllowedHosts": "*"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Calabonga.UnitOfWork" Version="3.0.1" />
<PackageReference Include="Calabonga.UnitOfWork" Version="3.1.0" />
<PackageReference Include="OperationResultCore" Version="4.0.1" />
<PackageReference Include="Calabonga.PredicatesBuilder" Version="2.0.1" />
<PackageReference Include="Calabonga.Microservices.Core" Version="4.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.5" />
</ItemGroup>

<ItemGroup>
Expand Down

This file was deleted.