refactroing, improvements, fixes, etc...
This commit is contained in:
parent
8da8b65892
commit
986e70bfe5
|
|
@ -35,9 +35,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AyCode.Services.Server", "A
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AyCode.Services.Server.Tests", "AyCode.Services.Server.Tests\AyCode.Services.Server.Tests.csproj", "{9AC9AF60-280A-4871-A7FA-69AB4D0C858A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AyCode.Core.Tests.Internal", "AyCode.Core.Tests.Internal\AyCode.Core.Tests.Internal.csproj", "{DE2DD6A4-A906-4BA6-8AAA-2A0433DF523F}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AyCode.Core.Tests.Internal", "AyCode.Core.Tests.Internal\AyCode.Core.Tests.Internal.csproj", "{DE2DD6A4-A906-4BA6-8AAA-2A0433DF523F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AyCode.Database.Tests.Internal", "AyCode.Database.Tests.Internal\AyCode.Database.Tests.Internal.csproj", "{73261A8C-FB41-4C4C-90D4-ED5EEC991413}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AyCode.Database.Tests.Internal", "AyCode.Database.Tests.Internal\AyCode.Database.Tests.Internal.csproj", "{73261A8C-FB41-4C4C-90D4-ED5EEC991413}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
|
@ -109,11 +109,9 @@ Global
|
|||
{DE2DD6A4-A906-4BA6-8AAA-2A0433DF523F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DE2DD6A4-A906-4BA6-8AAA-2A0433DF523F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DE2DD6A4-A906-4BA6-8AAA-2A0433DF523F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DE2DD6A4-A906-4BA6-8AAA-2A0433DF523F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{73261A8C-FB41-4C4C-90D4-ED5EEC991413}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{73261A8C-FB41-4C4C-90D4-ED5EEC991413}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{73261A8C-FB41-4C4C-90D4-ED5EEC991413}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{73261A8C-FB41-4C4C-90D4-ED5EEC991413}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
|||
|
|
@ -10,13 +10,24 @@ public interface IAcConsoleLogWriter : IAcTextLogWriterBase
|
|||
public class AcConsoleLogWriter : AcTextLogWriterBase, IAcConsoleLogWriter
|
||||
{
|
||||
protected AcConsoleLogWriter() : this(null)
|
||||
{ }
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
protected AcConsoleLogWriter(string? categoryName = null) : base(categoryName)
|
||||
{ }
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public AcConsoleLogWriter(AppType appType, LogLevel logLevel, string? categoryName = null) : base(appType, logLevel, categoryName)
|
||||
{ }
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
private static void Initialize()
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
}
|
||||
|
||||
protected override void WriteText(string? logText)
|
||||
{
|
||||
|
|
@ -24,10 +35,10 @@ public class AcConsoleLogWriter : AcTextLogWriterBase, IAcConsoleLogWriter
|
|||
|
||||
//lock (ForWriterLock)
|
||||
{
|
||||
//if (logLevel > LogLevel.Trace && logLevel < LogLevel.Suggest)
|
||||
if (LogLevel is > LogLevel.Trace and < LogLevel.Suggest)
|
||||
{
|
||||
Console.WriteLine(logText);
|
||||
return;
|
||||
//return;
|
||||
}
|
||||
|
||||
if (LogLevel <= LogLevel.Trace)
|
||||
|
|
|
|||
|
|
@ -84,4 +84,8 @@ public abstract class AcLogWriterBase : IAcLogWriterBase
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public virtual void Write(IAcLogItemClient logItem)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
using System.Security.AccessControl;
|
||||
using AyCode.Core.Consts;
|
||||
using AyCode.Core.Enums;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
|
@ -109,4 +110,9 @@ public abstract class AcLoggerBase : IAcLoggerBase
|
|||
{
|
||||
if (LogLevel <= logLevel) LogWriters.ForEach(x => x.Write(appType, logLevel, logText, callerMemberName, categoryName ?? CategoryName, errorType, exMessage));
|
||||
}
|
||||
|
||||
public void Write(IAcLogItemClient logItem)
|
||||
{
|
||||
if (LogLevel <= logItem.LogLevel) LogWriters.ForEach(x => x.Write(logItem));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using AyCode.Core.Enums;
|
||||
using AyCode.Core.Consts;
|
||||
using AyCode.Core.Enums;
|
||||
using AyCode.Utils.Extensions;
|
||||
|
||||
namespace AyCode.Core.Loggers;
|
||||
|
|
@ -25,26 +26,37 @@ public abstract class AcTextLogWriterBase : AcLogWriterBase, IAcTextLogWriterBas
|
|||
|
||||
}
|
||||
|
||||
public override void Write(IAcLogItemClient logItem)
|
||||
{
|
||||
if (logItem.LogLevel < LogLevel) return;
|
||||
|
||||
WriteText(GetDiagnosticText(logItem));
|
||||
}
|
||||
|
||||
protected virtual void WriteText(string? logText)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected virtual string GetDiagnosticText(LogLevel logLevel, string? logText, string? callerMemberName, string? categoryName = null, Exception? ex = null)
|
||||
protected string GetDiagnosticText(IAcLogItemClient logItem)
|
||||
=> GetDiagnosticText(logItem.TimeStampUtc, logItem.AppType, logItem.LogLevel, logItem.ThreadId, logItem.Text, logItem.CallerName, logItem.CategoryName, logItem.ErrorType, logItem.Exception);
|
||||
|
||||
protected string GetDiagnosticText(LogLevel logLevel, string? logText, string? callerMemberName, string? categoryName = null, Exception? ex = null)
|
||||
=> GetDiagnosticText(AppType, logLevel, logText, callerMemberName, categoryName, ex?.GetType().Name, ex?.ToString());
|
||||
|
||||
protected virtual string GetDiagnosticText(AppType appType, LogLevel logLevel, string? logText, string? callerMemberName, string? categoryName, string? errorType, string? exMessage)
|
||||
protected string GetDiagnosticText(AppType appType, LogLevel logLevel, string? logText, string? callerMemberName, string? categoryName, string? errorType, string? exMessage)
|
||||
=> GetDiagnosticText(DateTime.UtcNow, appType, logLevel, Environment.CurrentManagedThreadId, logText, callerMemberName, categoryName, errorType, exMessage);
|
||||
|
||||
protected string GetDiagnosticText(DateTime utcNow, AppType appType, LogLevel logLevel, int threadId, string? logText, string? callerMemberName, string? categoryName, string? errorType, string? exMessage)
|
||||
{
|
||||
if (LogLevel > logLevel) return string.Empty;
|
||||
|
||||
var threadId = Environment.CurrentManagedThreadId;
|
||||
|
||||
if(categoryName.IsNullOrWhiteSpace()) categoryName = CategoryName;
|
||||
|
||||
return $"[{DateTime.Now:HH:mm:ss.fff}] [{appType.ToString()[0]}] {"[" + logLevel + "]",-9} {"[" + categoryName + "->" + callerMemberName + "]",-54} {"[" + threadId + "]",5} {logText}{ErrorText(errorType, exMessage)}";
|
||||
return $"[{utcNow.ToLocalTime():HH:mm:ss.fff}] [{appType.ToString()[0]}] {"[" + logLevel + "]",-9} {"[" + categoryName + "->" + callerMemberName + "]",-54} {"[" + threadId + "]",5} {logText}{ErrorText(errorType, exMessage)}";
|
||||
}
|
||||
|
||||
protected virtual string ErrorText(Exception? ex)
|
||||
protected string ErrorText(Exception? ex)
|
||||
{
|
||||
return ex == null ? string.Empty : ErrorText(ex.GetType().Name, ex.ToString());
|
||||
}
|
||||
|
|
@ -53,6 +65,6 @@ public abstract class AcTextLogWriterBase : AcLogWriterBase, IAcTextLogWriterBas
|
|||
{
|
||||
if (errorType.IsNullOrWhiteSpace() && exMessage.IsNullOrWhiteSpace()) return string.Empty;
|
||||
|
||||
return string.IsNullOrWhiteSpace(errorType) ? string.Empty : $"{Environment.NewLine}[{errorType.ToUpper()}]: {exMessage}";
|
||||
return string.IsNullOrWhiteSpace(errorType) ? string.Empty : $"{AcEnv.NL}[{errorType.ToUpper()}]: {exMessage}";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
using AyCode.Core.Enums;
|
||||
using AyCode.Core.Loggers;
|
||||
using AyCode.Interfaces.Entities;
|
||||
|
||||
namespace AyCode.Entities.LogItems;
|
||||
namespace AyCode.Core.Loggers;
|
||||
|
||||
public interface IAcLogItemClient
|
||||
{
|
||||
public DateTime TimeStampUtc { get; set; }
|
||||
|
||||
public AppType AppType { get; set; }
|
||||
public LogLevel LogLevel { get; set; }
|
||||
public int ThreadId { get; set; }
|
||||
|
|
@ -29,4 +29,5 @@ public interface IAcLogWriterBase
|
|||
public void Write(AppType appType, LogLevel logLevel, string? logText, string? callerMemberName, string? categoryName, Exception? ex);
|
||||
public void Write(AppType appType, LogLevel logLevel, string? logText, string? callerMemberName, string? categoryName, string? errorType, string? exMessage);
|
||||
|
||||
public void Write(IAcLogItemClient logItem);
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ using AyCode.Core.Helpers;
|
|||
using AyCode.Core.Loggers;
|
||||
using AyCode.Database.DbContexts.Loggers;
|
||||
using AyCode.Entities;
|
||||
using AyCode.Entities.LogItems;
|
||||
using AyCode.Entities.Server.LogItems;
|
||||
using AyCode.Interfaces.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AyCode.Database;
|
||||
|
||||
|
|
@ -26,6 +26,8 @@ public class AcDbLogItemWriter<TLoggerDbContext, TLogItem> : AcLogItemWriterBase
|
|||
|
||||
protected override void WriteLogItemCallback(TLogItem logItem)
|
||||
{
|
||||
//using var ctx = Activator.CreateInstance<TLoggerDbContext>();
|
||||
|
||||
_ctx.LogItems.Add(logItem);
|
||||
_ctx.SaveChanges();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -21,8 +21,12 @@ public abstract class AcDalBase<TDbContext> : IAcDalBase<TDbContext> where TDbCo
|
|||
|
||||
public bool AutoCloseSession { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Do not use it! Use Session or Transaction... - J.
|
||||
/// </summary>
|
||||
public TDbContext Context { get; private set; }
|
||||
|
||||
public Mutex MutextLock { get; } = new();
|
||||
//protected AcDalBase()
|
||||
//{
|
||||
// Name = $"{GetType().Name}";
|
||||
|
|
|
|||
|
|
@ -10,7 +10,12 @@ public interface IAcDalBase //: IDisposable
|
|||
public interface IAcDalBase<TDbContext> : IAcDalBase where TDbContext : AcDbContextBase
|
||||
{
|
||||
public bool AutoCloseSession { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Do not use it! Use Session or Transaction... - J.
|
||||
/// </summary>
|
||||
public TDbContext Context { get; }
|
||||
public Mutex MutextLock { get; }
|
||||
|
||||
public TDbContext CreateDbContext();
|
||||
public void CloseDbContext(ref TDbContext? ctx);
|
||||
|
|
|
|||
|
|
@ -1,12 +1,19 @@
|
|||
using AyCode.Database.DbSets.Loggers;
|
||||
using AyCode.Entities.LogItems;
|
||||
using AyCode.Entities.Server.LogItems;
|
||||
using AyCode.Interfaces.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Identity.Client;
|
||||
|
||||
namespace AyCode.Database.DbContexts.Loggers;
|
||||
|
||||
public class AcLoggerDbContextBase<TLogItem> : AcDbContextBase, IAcLoggerDbContextBase<TLogItem> where TLogItem : class, IAcLogItem
|
||||
{
|
||||
public DbSet<TLogItem> LogItems { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
|
||||
optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
using AyCode.Database.DbSets.Loggers;
|
||||
using AyCode.Entities.LogItems;
|
||||
using AyCode.Entities.Server.LogItems;
|
||||
using AyCode.Interfaces.Entities;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using AyCode.Entities.LogItems;
|
||||
using AyCode.Entities.Server.LogItems;
|
||||
using AyCode.Entities.Server.LogItems;
|
||||
using AyCode.Interfaces.Entities;
|
||||
using AyCode.Interfaces.Users;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using AyCode.Database.DataLayers;
|
||||
using AyCode.Database.DbContexts;
|
||||
using AyCode.Interfaces.Entities;
|
||||
using AyCode.Utils.Extensions;
|
||||
|
||||
namespace AyCode.Database.Extensions;
|
||||
|
||||
|
|
@ -15,16 +16,22 @@ public static class AcDalExtension
|
|||
|
||||
public static TResultType Session<TDbContext, TResultType>(this IAcDalBase<TDbContext> acDal, Func<TDbContext, TResultType> callback) where TDbContext : AcDbContextBase
|
||||
{
|
||||
using var ctx = acDal.CreateDbContext();
|
||||
|
||||
return ctx.Session(callback);
|
||||
//using var ctx = acDal.CreateDbContext();
|
||||
|
||||
using (acDal.MutextLock.UseWaitOne())
|
||||
{
|
||||
return acDal.Context.Session(callback);
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<TEntity> Session<TDbContext, TEntity>(this IAcDalBase<TDbContext> acDal, Func<TDbContext, IQueryable<TEntity>> callback) where TEntity : IEntity where TDbContext : AcDbContextBase
|
||||
{
|
||||
using var ctx = acDal.CreateDbContext();
|
||||
|
||||
return ctx.Session(callback);
|
||||
//using var ctx = acDal.CreateDbContext();
|
||||
|
||||
using (acDal.MutextLock.UseWaitOne())
|
||||
{
|
||||
return acDal.Context.Session(callback);
|
||||
}
|
||||
}
|
||||
|
||||
public static Task<bool> TransactionAsync<TDbContext>(this IAcDalBase<TDbContext> acDal, Func<TDbContext, bool> callbackTransactionBody, bool throwException = false) where TDbContext : AcDbContextBase
|
||||
|
|
@ -32,8 +39,11 @@ public static class AcDalExtension
|
|||
|
||||
public static bool Transaction<TDbContext>(this IAcDalBase<TDbContext> acDal, Func<TDbContext, bool> callbackTransactionBody, bool throwException = false) where TDbContext : AcDbContextBase
|
||||
{
|
||||
using var ctx = acDal.CreateDbContext();
|
||||
|
||||
return ctx.Transaction(callbackTransactionBody, throwException);
|
||||
//using var ctx = acDal.CreateDbContext();
|
||||
|
||||
using (acDal.MutextLock.UseWaitOne())
|
||||
{
|
||||
return acDal.Context.Transaction(callbackTransactionBody, throwException);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@
|
|||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using AyCode.Core.Enums;
|
||||
using AyCode.Core.Loggers;
|
||||
using AyCode.Entities.LogItems;
|
||||
|
||||
namespace AyCode.Entities.Server.LogItems;
|
||||
|
||||
|
|
@ -13,10 +12,7 @@ public class AcLogItem : AcLogItemClient, IAcLogItem
|
|||
public int Id { get; set; }
|
||||
|
||||
public int LogHeaderId { get; set; }
|
||||
public DateTime TimeStampUtc { get; set; }
|
||||
|
||||
public AcLogItem()
|
||||
{
|
||||
TimeStampUtc = DateTime.UtcNow;
|
||||
}
|
||||
public AcLogItem() : base()
|
||||
{ }
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
using AyCode.Core.Enums;
|
||||
using AyCode.Core.Loggers;
|
||||
using AyCode.Entities.LogItems;
|
||||
using AyCode.Interfaces.Entities;
|
||||
|
||||
namespace AyCode.Entities.Server.LogItems;
|
||||
|
|
@ -8,5 +7,4 @@ namespace AyCode.Entities.Server.LogItems;
|
|||
public interface IAcLogItem : IAcLogItemClient, IEntityInt
|
||||
{
|
||||
public int LogHeaderId { get; set; }
|
||||
public DateTime TimeStampUtc { get; set; }
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
using AyCode.Core.Enums;
|
||||
using AyCode.Core.Helpers;
|
||||
using AyCode.Core.Loggers;
|
||||
using AyCode.Entities.LogItems;
|
||||
using AyCode.Interfaces.Entities;
|
||||
using AyCode.Utils.Extensions;
|
||||
using System.Collections.Concurrent;
|
||||
|
|
@ -23,10 +22,11 @@ public abstract class AcLogItemWriterBase<TLogItem> : AcLogWriterBase where TLog
|
|||
{
|
||||
}
|
||||
|
||||
protected virtual TLogItem CreateLogItem(AppType appType, int threadId, LogLevel logLevel, string? logText, string? callerMemberName, string? categoryName = null, string? errorType = null, string? exMessage = null)
|
||||
protected virtual TLogItem CreateLogItem(DateTime utcNow, AppType appType, int threadId, LogLevel logLevel, string? logText, string? callerMemberName, string? categoryName = null, string? errorType = null, string? exMessage = null)
|
||||
{
|
||||
var logItem = Activator.CreateInstance<TLogItem>();
|
||||
|
||||
|
||||
logItem.TimeStampUtc = utcNow;
|
||||
logItem.AppType = appType;
|
||||
logItem.LogLevel = logLevel;
|
||||
logItem.CategoryName = categoryName ?? CategoryName;
|
||||
|
|
@ -40,21 +40,25 @@ public abstract class AcLogItemWriterBase<TLogItem> : AcLogWriterBase where TLog
|
|||
return logItem;
|
||||
}
|
||||
|
||||
public override void Write(IAcLogItemClient logItem)
|
||||
=> WriteLogItemAsync(logItem as TLogItem);
|
||||
|
||||
public override void Write(AppType appType, LogLevel logLevel, string? logText, string? callerMemberName, string? categoryName, string? errorType, string? exMessage)
|
||||
=> WriteAsync(appType, logLevel, logText, callerMemberName, categoryName, errorType, exMessage);
|
||||
|
||||
protected virtual void WriteAsync(AppType appType, LogLevel logLevel, string? logText, string? callerMemberName, string? categoryName, string? errorType, string? exMessage)
|
||||
protected virtual void WriteAsync(AppType appType, LogLevel logLevel, string? logText, string? callerMemberName, string? categoryName, string? errorType, string? exMessage)
|
||||
{
|
||||
if (logLevel < LogLevel) return;
|
||||
|
||||
var utcNow = DateTime.UtcNow;
|
||||
var threadId = Environment.CurrentManagedThreadId;
|
||||
|
||||
TaskHelper.RunOnThreadPool(() => WriteLogItem(CreateLogItem(appType, threadId, logLevel, logText, callerMemberName, categoryName, errorType, exMessage)));
|
||||
TaskHelper.RunOnThreadPool(() => WriteLogItem(CreateLogItem(utcNow, appType, threadId, logLevel, logText, callerMemberName, categoryName, errorType, exMessage)));
|
||||
}
|
||||
|
||||
public void WriteLogItemAsync(TLogItem logItem)
|
||||
public void WriteLogItemAsync(TLogItem? logItem)
|
||||
{
|
||||
if (logItem.LogLevel < LogLevel) return;
|
||||
if (logItem == null || logItem.LogLevel < LogLevel) return;
|
||||
|
||||
TaskHelper.RunOnThreadPool(() => WriteLogItem(logItem));
|
||||
}
|
||||
|
|
@ -72,7 +76,9 @@ public abstract class AcLogItemWriterBase<TLogItem> : AcLogWriterBase where TLog
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("ERRORORROROR! " + AcEnv.NL + ex);
|
||||
Console.WriteLine($@"ERROR!!! {nameof(AcLogItemWriterBase<TLogItem>)}->WriteLogItem; ex: {ex.Message}{AcEnv.NL}{AcEnv.NL}{ex}");
|
||||
//Console.WriteLine("ERRORORROROR! " + AcEnv.NL + ex);
|
||||
//throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,32 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using AyCode.Core.Enums;
|
||||
using AyCode.Core.Interfaces;
|
||||
using AyCode.Core.Loggers;
|
||||
using AyCode.Core.Enums;
|
||||
|
||||
namespace AyCode.Entities.LogItems;
|
||||
namespace AyCode.Core.Loggers;
|
||||
|
||||
public class AcLogItemClient : IAcLogItemClient
|
||||
{
|
||||
public DateTime TimeStampUtc { get; set; }
|
||||
|
||||
public AppType AppType { get; set; }
|
||||
public LogLevel LogLevel { get; set; }
|
||||
public int ThreadId { get; set; }
|
||||
public int ThreadId { get; set; } = Environment.CurrentManagedThreadId;
|
||||
public string? CategoryName { get; set; }
|
||||
public string? CallerName { get; set; }
|
||||
public string? Text { get; set; }
|
||||
public string? ErrorType { get; set; }
|
||||
public string? Exception { get; set; }
|
||||
|
||||
public override string? ToString() => Text ?? base.ToString();
|
||||
|
||||
//public string ErrorText() => string.IsNullOrWhiteSpace(ErrorType) ? string.Empty : $"{AcEnv.NL}[{ErrorType.ToUpper()}]: {Exception}";
|
||||
|
||||
//public string ToMinimalText() => $"{"[" + CategoryName + "->" + CallerName + "]"} - {"[" + ThreadId + "]", 5} {Text}{ErrorText()}";
|
||||
|
||||
//public string ToNormalText()
|
||||
// => $"{"[" + LogLevel + "]",-9} {"[" + CategoryName + "->" + CallerName + "]"} - {"[" + ThreadId + "]", 5} {Text}{ErrorText()}";
|
||||
|
||||
//public string ToDetailText()
|
||||
// => $"[{TimeStampUtc.ToLocalTime():HH:mm:ss.fff}] {"[" + LogLevel + "]",-9} {"[" + CategoryName + "->" + CallerName + "]", -55} {"[" + ThreadId + "]", 5} {Text}{ErrorText()}";
|
||||
|
||||
//public string ToDiagnosticText()
|
||||
// => $"[{TimeStampUtc.ToLocalTime():HH:mm:ss.fff}] [{AppType.ToString()[0]}] {"[" + LogLevel + "]",-9} {"[" + CategoryName + "->" + CallerName + "]", -54} {"[" + ThreadId + "]", 5} {Text}{ErrorText()}";
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="SendGrid" Version="9.29.3" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -1,35 +1,44 @@
|
|||
using AyCode.Core.Enums;
|
||||
using AyCode.Core.Loggers;
|
||||
using AyCode.Entities;
|
||||
using AyCode.Entities.LogItems;
|
||||
using AyCode.Interfaces.Entities;
|
||||
using static System.Net.WebRequestMethods;
|
||||
using System;
|
||||
using System.Net;
|
||||
|
||||
namespace AyCode.Services.Loggers;
|
||||
|
||||
public abstract class AcHttpClientLogItemWriter<TLogItem> : AcLogItemWriterBase<TLogItem> where TLogItem : class, IAcLogItemClient
|
||||
public abstract class AcHttpClientLogItemWriter<TLogItem> : AcLogItemWriterBase<TLogItem>, IAcLogWriterClientBase where TLogItem : class, IAcLogItemClient
|
||||
{
|
||||
protected HttpClient _httpClient;
|
||||
protected readonly HttpClientHandler _httpClientHandler;
|
||||
protected HttpClientHandler _httpClientHandler;
|
||||
|
||||
protected AcHttpClientLogItemWriter(HttpClient httpClient) : base(AppType.Web, LogLevel.Detail)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
//_httpClient = httpClient;
|
||||
|
||||
Initialize(httpClient.BaseAddress, httpClient.DefaultRequestVersion, httpClient.DefaultVersionPolicy);
|
||||
}
|
||||
|
||||
protected AcHttpClientLogItemWriter(string? categoryName = null) : base(categoryName)
|
||||
{
|
||||
_httpClientHandler = new HttpClientHandler();
|
||||
_httpClient = new HttpClient(_httpClientHandler, false);
|
||||
Initialize(null, HttpVersion.Version20, HttpVersionPolicy.RequestVersionOrHigher);
|
||||
}
|
||||
|
||||
protected AcHttpClientLogItemWriter(AppType appType, LogLevel logLevel, string? categoryName = null) : base(appType, logLevel, categoryName)
|
||||
{
|
||||
_httpClientHandler = new HttpClientHandler();
|
||||
_httpClient = new HttpClient(_httpClientHandler, false);
|
||||
Initialize(null, HttpVersion.Version20, HttpVersionPolicy.RequestVersionOrHigher);
|
||||
}
|
||||
|
||||
private void Initialize(Uri? baseAddress, Version defaultRequestVersion, HttpVersionPolicy defaultVersionPolicy)
|
||||
{
|
||||
_httpClientHandler = new HttpClientHandler();
|
||||
_httpClient = new HttpClient(_httpClientHandler, false);
|
||||
|
||||
_httpClient.BaseAddress = baseAddress;
|
||||
_httpClient.DefaultRequestVersion = defaultRequestVersion;
|
||||
_httpClient.DefaultVersionPolicy = defaultVersionPolicy;
|
||||
}
|
||||
|
||||
public override void Write(AppType appType, LogLevel logLevel, string? logText, string? callerMemberName, string? categoryName, string? errorType, string? exMessage)
|
||||
=> WriteLogItem(CreateLogItem(DateTime.UtcNow, appType, Environment.CurrentManagedThreadId, logLevel, logText, callerMemberName, categoryName, errorType, exMessage));
|
||||
|
||||
//protected override void WriteLogItem(TLogItem logItem, Action? callback = null)
|
||||
//{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
using AyCode.Core.Loggers;
|
||||
|
||||
namespace AyCode.Services.Loggers;
|
||||
|
||||
public interface IAcLogWriterClientBase : IAcLogWriterBase
|
||||
{}
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
Loading…
Reference in New Issue