62 lines
2.0 KiB
C#
62 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using JNPF.Common.Contracts;
|
|
using JNPF.Logging;
|
|
using Microsoft.Extensions.Logging;
|
|
using SqlSugar;
|
|
using Tnb.WarehouseMgr.Entities;
|
|
|
|
namespace Tnb.WarehouseMgr
|
|
{
|
|
public class BaseWareHouseService<T> : BaseWareHouseService
|
|
{
|
|
protected static Dictionary<string, object> _elevatorMap = new Dictionary<string, object>();
|
|
|
|
public BaseWareHouseService(ISqlSugarClient db)
|
|
{
|
|
if (_elevatorMap.Count < 1)
|
|
{
|
|
Task.Run(async () =>
|
|
{
|
|
_elevatorMap = await db.Queryable<WmsElevatorH>().ToDictionaryAsync(x => x.elevator_id, x => x.elevator_code);
|
|
});
|
|
}
|
|
}
|
|
|
|
protected ILogger Logger => LoggerFactory.Create(builder => builder.AddFile($"{AppContext.BaseDirectory}/logs/custom{DateTime.Now:yyyyMMdd}.log", cfgOpts =>
|
|
{
|
|
|
|
//cfgOpts.DateFormat = "yyyy-MM-dd HH:mm:ss.fff";
|
|
cfgOpts.MessageFormat = (logMsg) =>
|
|
{
|
|
Span<char> span = logMsg.LogLevel.ToString().ToCharArray();
|
|
var sb = new StringBuilder();
|
|
sb.Append($"{span.Slice(0, 4)} ");
|
|
sb.Append($"{logMsg.LogName} ");
|
|
sb.Append($"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} ");
|
|
sb.Append($"#{logMsg.EventId.Id} ");
|
|
sb.Append(logMsg.Message + " ");
|
|
sb.Append(logMsg.Exception?.ToString());
|
|
return sb.ToString();
|
|
};
|
|
|
|
})).CreateLogger<T>();
|
|
}
|
|
|
|
public static class CustomLoggerExtenstions
|
|
{
|
|
public static void Information(this ILogger logger, string message, params object[] parameters)
|
|
{
|
|
logger.LogInformation(message, parameters);
|
|
}
|
|
|
|
public static void Error(this ILogger logger, string message, Exception ex, params object[] parameters)
|
|
{
|
|
logger.LogError(ex, message, parameters);
|
|
}
|
|
}
|
|
}
|