From 2dcee4b452805a68679c55629397558196d34611 Mon Sep 17 00:00:00 2001 From: gani shoiynbay Date: Fri, 14 Jul 2023 14:03:46 +0600 Subject: [PATCH 1/2] =?UTF-8?q?=D0=AF=20=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D0=BD=D0=B8=D0=BB=20=D0=BF=D0=B5=D1=80=D0=B2=D0=BE=D0=B5=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5.=201)=D0=94=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20=D1=81=D0=B2=D0=B0=D0=B3=D0=B3?= =?UTF-8?q?=D0=B5=D1=80=202)=D0=9F=D0=B5=D1=80=D0=B5=D0=B2=D0=B5=D0=BB=20?= =?UTF-8?q?=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20todo=20?= =?UTF-8?q?=D0=BB=D0=B8=D1=81=D1=82=D0=B0=20=D0=B2=20=D0=B1=D0=B0=D0=B7?= =?UTF-8?q?=D1=83.=20=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20=D1=85=D0=B0=D1=80?= =?UTF-8?q?=D0=B4=20=D0=BA=D0=BE=D0=B4=20=D1=81=D1=82=D1=80=D0=BE=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=81=D0=BE=D0=B5=D0=B4=D0=B8=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B2=20appsettings=203)=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=BB=20=D0=BB=D0=BE=D0=B3=D0=B3=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20Serilog=204)=D1=81=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D0=BB=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3=20=D1=80=D0=B0=D0=B7=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B8=D0=BB=20=20Data=20Access=20Layer,=20Business=20Layer.=20?= =?UTF-8?q?=D0=A2=D0=B0=D0=BA=20=D0=B6=D0=B5=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=BB=20=D0=BC=D0=B0=D0=BF=D0=BF=D0=B5=D1=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- Controllers/TodoItemsController.cs | 54 ++++++++++++------- IToDoServices/IToDoService.cs | 10 ++++ IToDoServices/ToDoService.cs | 31 +++++++++++ Mapping/ToDoMappingProfile.cs | 14 +++++ .../20230713084140_InitialCreate.Designer.cs | 46 ++++++++++++++++ Migrations/20230713084140_InitialCreate.cs | 31 +++++++++++ Migrations/TodoContextModelSnapshot.cs | 44 +++++++++++++++ Program.cs | 3 +- Repositories/Entities/IToDoRepository.cs | 9 ++++ Repositories/Entities/ToDoRepository.cs | 12 +++++ Repositories/IRepositoryBase.cs | 15 ++++++ Repositories/RepositoryBase.cs | 23 ++++++++ ServiceExtensions.cs | 47 ++++++++++++++++ Startup.cs | 29 ++++++---- TodoApiDTO.csproj | 18 ++++++- appsettings.json | 3 ++ serilogsettings.Development.json | 1 + serilogsettings.Docker.json | 22 ++++++++ serilogsettings.json | 54 +++++++++++++++++++ 20 files changed, 436 insertions(+), 33 deletions(-) create mode 100644 IToDoServices/IToDoService.cs create mode 100644 IToDoServices/ToDoService.cs create mode 100644 Mapping/ToDoMappingProfile.cs create mode 100644 Migrations/20230713084140_InitialCreate.Designer.cs create mode 100644 Migrations/20230713084140_InitialCreate.cs create mode 100644 Migrations/TodoContextModelSnapshot.cs create mode 100644 Repositories/Entities/IToDoRepository.cs create mode 100644 Repositories/Entities/ToDoRepository.cs create mode 100644 Repositories/IRepositoryBase.cs create mode 100644 Repositories/RepositoryBase.cs create mode 100644 ServiceExtensions.cs create mode 100644 serilogsettings.Development.json create mode 100644 serilogsettings.Docker.json create mode 100644 serilogsettings.json diff --git a/.gitignore b/.gitignore index 4ce6fdde..961981f4 100644 --- a/.gitignore +++ b/.gitignore @@ -337,4 +337,5 @@ ASALocalRun/ .localhistory/ # BeatPulse healthcheck temp database -healthchecksdb \ No newline at end of file +healthchecksdb +/serilogsettings.Staging.json diff --git a/Controllers/TodoItemsController.cs b/Controllers/TodoItemsController.cs index 0ef138e7..493fc7e4 100644 --- a/Controllers/TodoItemsController.cs +++ b/Controllers/TodoItemsController.cs @@ -1,42 +1,47 @@ +using AutoMapper; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using TodoApi.Models; - +using TodoApiDTO.IToDoServices; namespace TodoApi.Controllers { [Route("api/[controller]")] [ApiController] public class TodoItemsController : ControllerBase { - private readonly TodoContext _context; - - public TodoItemsController(TodoContext context) + private IToDoService _toDoService; + private readonly IMapper _mapper; + protected readonly ILogger _logger; + public TodoItemsController(IToDoService toDoService, IMapper mapper, ILogger logger) { - _context = context; + _toDoService = toDoService; + _mapper = mapper; + _logger = logger; } [HttpGet] public async Task>> GetTodoItems() { - return await _context.TodoItems - .Select(x => ItemToDTO(x)) - .ToListAsync(); + _logger.LogInformation("Hello From logging"); + var result = _toDoService._todoRepository.FindAll().ToList(); + return _mapper.Map>(result); } [HttpGet("{id}")] public async Task> GetTodoItem(long id) { - var todoItem = await _context.TodoItems.FindAsync(id); + var todoItem = _toDoService._todoRepository.FindByCondition(x => x.Id == id).First(); if (todoItem == null) { return NotFound(); } - return ItemToDTO(todoItem); + return _mapper.Map(todoItem); } [HttpPut("{id}")] @@ -47,7 +52,7 @@ public async Task UpdateTodoItem(long id, TodoItemDTO todoItemDTO return BadRequest(); } - var todoItem = await _context.TodoItems.FindAsync(id); + var todoItem = _toDoService._todoRepository.FindByCondition(x => x.Id == id).First(); if (todoItem == null) { return NotFound(); @@ -58,7 +63,9 @@ public async Task UpdateTodoItem(long id, TodoItemDTO todoItemDTO try { - await _context.SaveChangesAsync(); + _toDoService._todoRepository.Update(todoItem); + _toDoService.Save(); + } catch (DbUpdateConcurrencyException) when (!TodoItemExists(id)) { @@ -77,8 +84,8 @@ public async Task> CreateTodoItem(TodoItemDTO todoItem Name = todoItemDTO.Name }; - _context.TodoItems.Add(todoItem); - await _context.SaveChangesAsync(); + _toDoService._todoRepository.Create(todoItem); + _toDoService.Save(); return CreatedAtAction( nameof(GetTodoItem), @@ -89,22 +96,29 @@ public async Task> CreateTodoItem(TodoItemDTO todoItem [HttpDelete("{id}")] public async Task DeleteTodoItem(long id) { - var todoItem = await _context.TodoItems.FindAsync(id); + var todoItem = _toDoService._todoRepository.FindByCondition(x => x.Id == id).First(); if (todoItem == null) { return NotFound(); } - _context.TodoItems.Remove(todoItem); - await _context.SaveChangesAsync(); + _toDoService._todoRepository.Delete(todoItem); + _toDoService.Save(); return NoContent(); } - private bool TodoItemExists(long id) => - _context.TodoItems.Any(e => e.Id == id); - + private bool TodoItemExists(long id) + { + var result = _toDoService._todoRepository.FindByCondition(x => x.Id == id).First(); + + if(result != null) + { + return true; + } + return false; + } private static TodoItemDTO ItemToDTO(TodoItem todoItem) => new TodoItemDTO { diff --git a/IToDoServices/IToDoService.cs b/IToDoServices/IToDoService.cs new file mode 100644 index 00000000..8357b8b8 --- /dev/null +++ b/IToDoServices/IToDoService.cs @@ -0,0 +1,10 @@ +using TodoApiDTO.Repositories.Entities; + +namespace TodoApiDTO.IToDoServices +{ + public interface IToDoService + { + IToDoRepository _todoRepository { get; } + void Save(); + } +} diff --git a/IToDoServices/ToDoService.cs b/IToDoServices/ToDoService.cs new file mode 100644 index 00000000..916d249f --- /dev/null +++ b/IToDoServices/ToDoService.cs @@ -0,0 +1,31 @@ +using TodoApi.Models; +using TodoApiDTO.Repositories.Entities; +using TodoApiDTO.Repositories.ToDo; + +namespace TodoApiDTO.IToDoServices +{ + public class ToDoService : IToDoService + { + private TodoContext _todoContext; + private IToDoRepository _toDoRepository; + + public IToDoRepository _todoRepository + { + get + { + if (_toDoRepository == null) { _toDoRepository = new ToDoRepository(_todoContext); } + return _toDoRepository; + } + } + + public ToDoService(TodoContext todoContext) + { + _todoContext = todoContext; + } + + public void Save() + { + _todoContext.SaveChanges(); + } + } +} diff --git a/Mapping/ToDoMappingProfile.cs b/Mapping/ToDoMappingProfile.cs new file mode 100644 index 00000000..ca56b926 --- /dev/null +++ b/Mapping/ToDoMappingProfile.cs @@ -0,0 +1,14 @@ +using AutoMapper; +using TodoApi.Models; + +namespace TodoApiDTO.Mapping +{ + public class ToDoMappingProfile : Profile + { + public ToDoMappingProfile() + { + CreateMap(); + } + + } +} diff --git a/Migrations/20230713084140_InitialCreate.Designer.cs b/Migrations/20230713084140_InitialCreate.Designer.cs new file mode 100644 index 00000000..ade61d8d --- /dev/null +++ b/Migrations/20230713084140_InitialCreate.Designer.cs @@ -0,0 +1,46 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using TodoApi.Models; + +namespace TodoApiDTO.Migrations +{ + [DbContext(typeof(TodoContext))] + [Migration("20230713084140_InitialCreate")] + partial class InitialCreate + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("TodoApi.Models.TodoItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("IsComplete") + .HasColumnType("bit"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("Secret") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("TodoItems"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20230713084140_InitialCreate.cs b/Migrations/20230713084140_InitialCreate.cs new file mode 100644 index 00000000..c65ba078 --- /dev/null +++ b/Migrations/20230713084140_InitialCreate.cs @@ -0,0 +1,31 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace TodoApiDTO.Migrations +{ + public partial class InitialCreate : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "TodoItems", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(nullable: true), + IsComplete = table.Column(nullable: false), + Secret = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_TodoItems", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "TodoItems"); + } + } +} diff --git a/Migrations/TodoContextModelSnapshot.cs b/Migrations/TodoContextModelSnapshot.cs new file mode 100644 index 00000000..9d5b3c3e --- /dev/null +++ b/Migrations/TodoContextModelSnapshot.cs @@ -0,0 +1,44 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using TodoApi.Models; + +namespace TodoApiDTO.Migrations +{ + [DbContext(typeof(TodoContext))] + partial class TodoContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("TodoApi.Models.TodoItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("IsComplete") + .HasColumnType("bit"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("Secret") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("TodoItems"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Program.cs b/Program.cs index b27ac16a..3f56944b 100644 --- a/Program.cs +++ b/Program.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using Serilog; namespace TodoApi { @@ -17,7 +18,7 @@ public static void Main(string[] args) } public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) + Host.CreateDefaultBuilder(args).UseSerilog() .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); diff --git a/Repositories/Entities/IToDoRepository.cs b/Repositories/Entities/IToDoRepository.cs new file mode 100644 index 00000000..b3752729 --- /dev/null +++ b/Repositories/Entities/IToDoRepository.cs @@ -0,0 +1,9 @@ +using TodoApi.Models; + +namespace TodoApiDTO.Repositories.Entities +{ + public interface IToDoRepository:IRepositoryBase + { + + } +} diff --git a/Repositories/Entities/ToDoRepository.cs b/Repositories/Entities/ToDoRepository.cs new file mode 100644 index 00000000..3ad4c8aa --- /dev/null +++ b/Repositories/Entities/ToDoRepository.cs @@ -0,0 +1,12 @@ +using TodoApi.Models; +using TodoApiDTO.Repositories.Entities; + +namespace TodoApiDTO.Repositories.ToDo +{ + public class ToDoRepository : RepositoryBase, IToDoRepository + { + public ToDoRepository(TodoContext repositoryContext) : base(repositoryContext) + { + } + } +} diff --git a/Repositories/IRepositoryBase.cs b/Repositories/IRepositoryBase.cs new file mode 100644 index 00000000..194d2926 --- /dev/null +++ b/Repositories/IRepositoryBase.cs @@ -0,0 +1,15 @@ +using System.Linq.Expressions; +using System.Linq; +using System; + +namespace TodoApiDTO.Repositories +{ + public interface IRepositoryBase + { + IQueryable FindAll(); + IQueryable FindByCondition(Expression> expression); + void Create(T entity); + void Update(T entity); + void Delete(T entity); + } +} diff --git a/Repositories/RepositoryBase.cs b/Repositories/RepositoryBase.cs new file mode 100644 index 00000000..d643e363 --- /dev/null +++ b/Repositories/RepositoryBase.cs @@ -0,0 +1,23 @@ +using System.Linq.Expressions; +using System.Linq; +using System; +using TodoApi.Models; +using Microsoft.EntityFrameworkCore; + +namespace TodoApiDTO.Repositories +{ + public abstract class RepositoryBase : IRepositoryBase where T : class + { + protected TodoContext RepositoryContext { get; set; } + public RepositoryBase(TodoContext repositoryContext) + { + RepositoryContext = repositoryContext; + } + public IQueryable FindAll() => RepositoryContext.Set().AsNoTracking(); + public IQueryable FindByCondition(Expression> expression) => + RepositoryContext.Set().Where(expression).AsNoTracking(); + public void Create(T entity) => RepositoryContext.Set().Add(entity); + public void Update(T entity) => RepositoryContext.Set().Update(entity); + public void Delete(T entity) => RepositoryContext.Set().Remove(entity); + } +} diff --git a/ServiceExtensions.cs b/ServiceExtensions.cs new file mode 100644 index 00000000..0e44c46a --- /dev/null +++ b/ServiceExtensions.cs @@ -0,0 +1,47 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Configuration; + +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Logging; + +using Serilog; + +using TodoApi.Models; +using System.IO; +using System.Text.Json; + +namespace TodoApiDTO +{ + public static class ServiceExtensions + { + public static Serilog.ILogger BuildSerilogLogger(this IWebHostEnvironment env) + { + var appAssembly = typeof(ServiceExtensions).Assembly; + var currentDirectory = Path.GetDirectoryName(appAssembly.Location); + + var configuration = new ConfigurationBuilder() + .SetBasePath(currentDirectory) + .AddJsonFile("serilogsettings.json", optional: false, reloadOnChange: false) + .AddEnvironmentVariables("ToDo") + .Build(); + + Log.Logger = new LoggerConfiguration() + .ReadFrom.Configuration(configuration) + .CreateLogger(); + + return Log.Logger; + } + + public static void LogRestApiCallStart(this Microsoft.Extensions.Logging.ILogger logger, object request, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "") + { + logger.LogDebug("Call ApiCall method {0}\n {1}", memberName, JsonSerializer.Serialize(request)); + } + + public static void ConfigureMySqlContext(this IServiceCollection services, IConfiguration config) + { + var connectionString = config["mysqlconnection:connectionString"]; + services.AddDbContext(o => o.UseSqlServer(connectionString)); + } + } +} \ No newline at end of file diff --git a/Startup.cs b/Startup.cs index bbfbc83d..24b27aa1 100644 --- a/Startup.cs +++ b/Startup.cs @@ -1,17 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; + using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpsPolicy; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using TodoApiDTO; +using TodoApiDTO.IToDoServices; +using TodoApiDTO.Mapping; using Microsoft.Extensions.Logging; -using TodoApi.Models; +using TodoApi.Controllers; +using Serilog; namespace TodoApi { @@ -27,9 +25,12 @@ public Startup(IConfiguration configuration) // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddDbContext(opt => - opt.UseInMemoryDatabase("TodoList")); + services.ConfigureMySqlContext(Configuration); + services.AddScoped(); + services.AddAutoMapper(typeof(ToDoMappingProfile)); services.AddControllers(); + services.AddSwaggerGen(); + } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -39,6 +40,14 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseDeveloperExceptionPage(); } + env.BuildSerilogLogger(); + app.UseSwagger(); + app.UseSwaggerUI(options => + { + options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1"); + options.RoutePrefix = string.Empty; + }); + app.UseHttpsRedirection(); diff --git a/TodoApiDTO.csproj b/TodoApiDTO.csproj index bba6f6af..543ec4e2 100644 --- a/TodoApiDTO.csproj +++ b/TodoApiDTO.csproj @@ -1,17 +1,33 @@ - + netcoreapp3.1 + + + runtime; build; native; contentfiles; analyzers; buildtransitive all + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + diff --git a/appsettings.json b/appsettings.json index d9d9a9bf..adb4a9e1 100644 --- a/appsettings.json +++ b/appsettings.json @@ -6,5 +6,8 @@ "Microsoft.Hosting.Lifetime": "Information" } }, + "mysqlconnection": { + "connectionString": "Data Source=(localdb)\\MSSQLLocalDB;Integrated Security=True" + }, "AllowedHosts": "*" } diff --git a/serilogsettings.Development.json b/serilogsettings.Development.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/serilogsettings.Development.json @@ -0,0 +1 @@ +{} diff --git a/serilogsettings.Docker.json b/serilogsettings.Docker.json new file mode 100644 index 00000000..38abb7a8 --- /dev/null +++ b/serilogsettings.Docker.json @@ -0,0 +1,22 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.Console" ], + "MinimumLevel": { + "Default": "Verbose", + "Override": { + "System": "Verbose", + "Microsoft": "Verbose", + "Microsoft.EntityFrameworkCore.Database.Command": "Verbose", + "Microsoft.EntityFrameworkCore.Query": "Verbose" + } + }, + "WriteTo": [ + { + "Name": "Console", + "Args": { + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} <{ThreadId}> [{Level:u3}] {Message:lj}{NewLine}{Exception}" + } + } + ] + } +} diff --git a/serilogsettings.json b/serilogsettings.json new file mode 100644 index 00000000..84fdf885 --- /dev/null +++ b/serilogsettings.json @@ -0,0 +1,54 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.Console" ], + "MinimumLevel": { + "Default": "Verbose", + "Override": { + "System": "Information", + "Microsoft": "Information", + "Microsoft.EntityFrameworkCore.Database.Command": "Information", + "Microsoft.EntityFrameworkCore.Query": "Information" + } + }, + "WriteTo": [ + { + "Name": "Async", + "Args": { + "configure": [ + { + "Name": "File", + "Args": { + "path": ".\\logs\\ToDo-.log", + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} <{ThreadId}> [{Level:u3}] {Message:lj}{NewLine}{Exception}", + "fileSizeLimitBytes": 104857600, // 100 MB + "rollingInterval": "Day", + "rollOnFileSizeLimit": true + } + }, + { + "Name": "Console", + "Args": { + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} <{ThreadId}> [{Level:u3}] {Message:lj}{NewLine}{Exception}" + } + } + ] + } + } + ], + "Enrich": [ "FromLogContext", "WithMachineName", "WithEnvironmentUserName", "WithThreadId" ], + "Destructure": [ + { + "Name": "ToMaximumDepth", + "Args": { "maximumDestructuringDepth": 4 } + }, + { + "Name": "ToMaximumStringLength", + "Args": { "maximumStringLength": 100 } + }, + { + "Name": "ToMaximumCollectionCount", + "Args": { "maximumCollectionCount": 10 } + } + ] + } +} From 02a318f5a73faea91911ba6f578b35a4b53722c6 Mon Sep 17 00:00:00 2001 From: gani shoiynbay Date: Tue, 18 Jul 2023 07:49:30 +0600 Subject: [PATCH 2/2] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D1=8C=20=D0=BB=D0=BE=D0=B3=D0=BE=D0=B2=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82=D0=BD=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controllers/TodoItemsController.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Controllers/TodoItemsController.cs b/Controllers/TodoItemsController.cs index 493fc7e4..7c033903 100644 --- a/Controllers/TodoItemsController.cs +++ b/Controllers/TodoItemsController.cs @@ -38,7 +38,7 @@ public async Task> GetTodoItem(long id) if (todoItem == null) { - return NotFound(); + _logger.LogError("Íå íàéäåíû ñïèñîê çàäà÷"); } return _mapper.Map(todoItem); @@ -49,12 +49,14 @@ public async Task UpdateTodoItem(long id, TodoItemDTO todoItemDTO { if (id != todoItemDTO.Id) { + _logger.LogError("Àéäè íå ñîâïàäàþò"); return BadRequest(); } var todoItem = _toDoService._todoRepository.FindByCondition(x => x.Id == id).First(); if (todoItem == null) { + _logger.LogError("Çàäà÷à íå íàéäåíà"); return NotFound(); } @@ -69,6 +71,7 @@ public async Task UpdateTodoItem(long id, TodoItemDTO todoItemDTO } catch (DbUpdateConcurrencyException) when (!TodoItemExists(id)) { + _logger.LogError("Çàäà÷à íå íàéäåíà"); return NotFound(); } @@ -100,6 +103,7 @@ public async Task DeleteTodoItem(long id) if (todoItem == null) { + _logger.LogError("Çàäà÷à íå íàéäåíà"); return NotFound(); }