Jelajahi Sumber

NLog日志存储到MySQL提交

Murphy 3 tahun lalu
induk
melakukan
3d2eb5169b
64 mengubah file dengan 828 tambahan dan 68 penghapusan
  1. 1 0
      MicroServices/Business/Business.Application/Business.Application.csproj
  2. 20 0
      MicroServices/Business/Business.Application/Quartz/LogHostedService.cs
  3. 34 0
      MicroServices/Business/Business.Application/Quartz/NLogJob.cs
  4. 8 3
      MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs
  5. 3 0
      MicroServices/Business/Business.Core/Business.Core.csproj
  6. 70 0
      MicroServices/Business/Business.Core/Utilities/NLogHelper.cs
  7. 8 0
      MicroServices/Business/Business.Host/Business.Host.csproj
  8. 20 1
      MicroServices/Business/Business.Host/BusinessHostModule.cs
  9. 7 2
      MicroServices/Business/Business.Host/Program.cs
  10. 1 0
      MicroServices/Business/Business.Host/appsettings.json
  11. 73 0
      MicroServices/Business/Business.Host/nlog.config
  12. 4 1
      MicroServices/Business/Business.HttpApi/Controllers/TestController.cs
  13. 3 3
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/DigitalManufacturing.Application.Contracts.csproj
  14. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/DigitalManufacturingApplicationContractsModule.cs
  15. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/DigitalManufacturingManagement/Dto/FileInfoDto.cs
  16. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/DigitalManufacturingManagement/Dto/GetFileInputDto.cs
  17. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/DigitalManufacturingManagement/IDigitalManufacturingAppService.cs
  18. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/Permissions/DigitalManufacturingPermissionDefinitionProvider.cs
  19. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/Permissions/DigitalManufacturingPermissions.cs
  20. 4 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application/DigitalManufacturing.Application.csproj
  21. 3 3
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application/DigitalManufacturingApplicationAutoMapperProfile.cs
  22. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application/DigitalManufacturingApplicationModule.cs
  23. 13 6
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application/DigitalManufacturingManagement/DigitalManufacturingAppService.cs
  24. 20 0
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application/Quartz/LogHostedService.cs
  25. 28 0
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application/Quartz/NLogJob.cs
  26. 14 0
      MicroServices/DigitalManufacturing/DigitalManufacturing.Core/DigitalManufacturing.Core.csproj
  27. 70 0
      MicroServices/DigitalManufacturing/DigitalManufacturing.Core/NLogHelper.cs
  28. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Domain/DigitalManufacturing.Domain.csproj
  29. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Domain/DigitalManufacturingDomainModule.cs
  30. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Domain/Enums/Enums.cs
  31. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.Domain/Models/FileInfo.cs
  32. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.Domain/Models/FileManager.cs
  33. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.EntityFrameworkCore/DigitalManufacturing.EntityFrameworkCore.csproj
  34. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.EntityFrameworkCore/EntityFrameworkCore/DigitalManufacturingDbContext.cs
  35. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.EntityFrameworkCore/EntityFrameworkCore/DigitalManufacturingDbContextModelCreatingExtensions.cs
  36. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.EntityFrameworkCore/EntityFrameworkCore/DigitalManufacturingEntityFrameworkCoreModule.cs
  37. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/DOP/DOPController.cs
  38. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/HomeController.cs
  39. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/Kanban/KanbanController.cs
  40. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/MES/MESController.cs
  41. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/QMS/QMSController.cs
  42. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/SIM/AndonController.cs
  43. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/SIM/SIMController.cs
  44. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/WMS/WMSController.cs
  45. 10 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/DigitalManufacturing.Host.csproj
  46. 36 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/DigitalManufacturingHostModule.cs
  47. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/EntityFrameworkCore/DigitalManufacturingMigrationDbContext.cs
  48. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/EntityFrameworkCore/DigitalManufacturingMigrationDbContextFactory.cs
  49. 7 4
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Program.cs
  50. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Startup.cs
  51. 2 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/appsettings.json
  52. 69 0
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/nlog.config
  53. 6 0
      MicroServices/DigitalManufacturing/DigitalManufacturing.sln
  54. 3 0
      MicroServices/Procurement/Procurement.Application/Procurement.Application.csproj
  55. 7 1
      MicroServices/Procurement/Procurement.Application/ProcurementManagement/ProcurementAppService.cs
  56. 20 0
      MicroServices/Procurement/Procurement.Application/Quartz/LogHostedService.cs
  57. 28 0
      MicroServices/Procurement/Procurement.Application/Quartz/NLogJob.cs
  58. 70 0
      MicroServices/Procurement/Procurement.Core/NLogHelper.cs
  59. 15 0
      MicroServices/Procurement/Procurement.Core/Procurement.Core.csproj
  60. 2 0
      MicroServices/Procurement/Procurement.Host/Procurement.Host.csproj
  61. 34 0
      MicroServices/Procurement/Procurement.Host/ProcurementHostModule.cs
  62. 2 1
      MicroServices/Procurement/Procurement.Host/Program.cs
  63. 69 0
      MicroServices/Procurement/Procurement.Host/nlog.config
  64. 6 0
      MicroServices/Procurement/Procurement.sln

+ 1 - 0
MicroServices/Business/Business.Application/Business.Application.csproj

@@ -11,6 +11,7 @@
 
   <ItemGroup>
     <PackageReference Include="Magicodes.IE.Pdf" Version="2.7.1" />
+    <PackageReference Include="NLog" Version="5.1.2" />
     <PackageReference Include="Quartz.AspNetCore" Version="3.6.2" />
     <PackageReference Include="Volo.Abp.AutoMapper" Version="6.0.0" />
     <PackageReference Include="Volo.Abp.Http.Client.IdentityModel" Version="6.0.0" />

+ 20 - 0
MicroServices/Business/Business.Application/Quartz/LogHostedService.cs

@@ -0,0 +1,20 @@
+using Microsoft.Extensions.Hosting;
+using NLog;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Business.Quartz
+{
+    //Nlog日志按月分表,需要每天凌晨检查是否存在表,不存在就要新建表,程序启动的时候也要检查一次。类似初始化
+    public class LogHostedService
+    {
+        public void LogInstall()
+        {
+            LogManager.Configuration.Install(new NLog.Config.InstallationContext());//每天0点执行一次
+        }
+    }
+}

+ 34 - 0
MicroServices/Business/Business.Application/Quartz/NLogJob.cs

@@ -0,0 +1,34 @@
+using Business.SyncDataManagement;
+using Quartz;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Business.Quartz
+{
+    public class NLogJob : IJob
+    {
+
+        /// <summary>
+        /// Nlog日志按月分表,需要每天凌晨检查是否存在表,不存在就要新建表,程序启动的时候也要检查一次。类似初始化
+        /// </summary>
+        public readonly LogHostedService _logHostedService;
+
+        /// <summary>
+        /// 构造函数
+        /// </summary>
+        public NLogJob(LogHostedService logHostedService)
+        {
+            _logHostedService = logHostedService;
+        }
+        public Task Execute(IJobExecutionContext context)
+        {
+            _logHostedService.LogInstall();
+
+            return Task.CompletedTask;
+        }
+    }
+}

+ 8 - 3
MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs

@@ -21,7 +21,9 @@ using System.Linq;
 using System.Linq.Dynamic.Core;
 using System.Threading.Tasks;
 using Volo.Abp.Application.Services;
+using Volo.Abp.DependencyInjection;
 using Volo.Abp.Domain.Repositories;
+using Volo.Abp.MultiTenancy;
 
 namespace Business.ResourceExamineManagement
 {
@@ -29,11 +31,11 @@ namespace Business.ResourceExamineManagement
     /// 资源检查
     /// </summary>
     //[Authorize(BusinessPermissions.ResourceExamine.Default)]
-    public class ResourceExamineAppService : ApplicationService, IResourceExamineAppService
+    public class ResourceExamineAppService : ApplicationService, IResourceExamineAppService, ITransientDependency
     {
         #region 服务
         SnowFlake help = new SnowFlake();
-
+        private readonly ICurrentTenant _currentTenant;
         /// <summary>
         /// 工艺路径
         /// </summary>
@@ -263,7 +265,8 @@ namespace Business.ResourceExamineManagement
             IRepository<ic_plan, long> mysql_ic_plan,
             PretreatmentAppService pretreatmentAppService,
             CalcBomViewAppService calcbomviewAppService,
-            PurchaseOrderAppService purchaseOrderAppService
+            PurchaseOrderAppService purchaseOrderAppService,
+            ICurrentTenant currentTenant
             )
         {
             _mes_technique = mes_technique;
@@ -310,6 +313,7 @@ namespace Business.ResourceExamineManagement
             _pretreatmentAppService = pretreatmentAppService;
             _CalcBomViewAppService = calcbomviewAppService;
             _purchaseOrderAppService = purchaseOrderAppService;
+            _currentTenant = currentTenant;
         }
         #endregion
 
@@ -340,6 +344,7 @@ namespace Business.ResourceExamineManagement
             crm_seorder sorder = _mysql_crm_seorder.GetListAsync(p => p.tenant_id == input.tenantId && p.factory_id == input.factoryId && p.Id == input.sorderId && !p.IsDeleted).Result.FirstOrDefault();
             if (sorder == null)
             {
+                new NLogHelper("ResourceExamineAppService").WriteLog("ReceiveResult", "订单数据不存在", _currentTenant.Id.ToString());
                 throw new NotImplementedException("订单数据不存在!");
             }
             //获取订单行数据

+ 3 - 0
MicroServices/Business/Business.Core/Business.Core.csproj

@@ -11,6 +11,9 @@
     <PackageReference Include="MongoDB.Driver" Version="2.19.0" />
     <PackageReference Include="MongoDB.Driver.Core" Version="2.19.0" />
     <PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.2" />
+    <PackageReference Include="NLog" Version="5.1.2" />
+    <PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" />
+    <PackageReference Include="NLog.Web.AspNetCore" Version="5.2.2" />
     <PackageReference Include="Spire.Barcode" Version="3.5.0" />
     <PackageReference Include="Spire.PDF" Version="4.11.3" />
     <PackageReference Include="Volo.Abp.Ddd.Domain" Version="6.0.0" />

+ 70 - 0
MicroServices/Business/Business.Core/Utilities/NLogHelper.cs

@@ -0,0 +1,70 @@
+using NLog;
+
+namespace Business.Core.Utilities
+{
+    /// <summary>
+    /// Nlog日志帮助类
+    /// </summary>
+    public class NLogHelper
+    {
+        #region 初始化
+        readonly Logger _logger;
+
+        private NLogHelper(Logger logger)
+        {
+            this._logger = logger;
+        }
+
+        /// <summary>
+        /// 自定义Logger,否则用默认的GetCurrentClassLogger
+        /// </summary>
+        /// <param name="name"></param>
+        public NLogHelper(string name) : this(LogManager.GetLogger(name))
+        {
+        }
+
+        /// <summary>
+        /// 默认 ${logger} (Default 文件夹下)
+        /// </summary>
+        public static NLogHelper Default { get; private set; }
+        static NLogHelper()
+        {
+            Default = new NLogHelper(LogManager.GetCurrentClassLogger());
+        }
+        #endregion
+
+        /// <summary>
+        /// 日志写入,默认info等级
+        /// </summary>
+        /// <param name="ModuleName">模块名称</param>
+        /// <param name="Msg">日志内容</param>
+        /// <param name="TenantId">租户Id</param>
+        public void WriteLog(string ModuleName,string Msg,string TenantId="")
+        {
+            LogEventInfo logEventInfo=new LogEventInfo();
+            logEventInfo.Properties["ModuleName"] = ModuleName;
+            logEventInfo.Properties["Msg"] = Msg;
+            logEventInfo.Properties["TenantId"] = TenantId;
+            logEventInfo.Level = LogLevel.Info;
+            _logger.Log(logEventInfo);
+        }
+
+        /// <summary>
+        /// 日志写入,自己传日志类别
+        /// </summary>
+        /// <param name="ModuleName">模块名称</param>
+        /// <param name="Msg">日志内容</param>
+        /// <param name="Level">日志级别</param>
+        /// <param name="TenantId">租户Id</param>
+        public void WriteLog(string ModuleName, string Msg,LogLevel Level, string TenantId = "")
+        {
+            
+            LogEventInfo logEventInfo = new LogEventInfo();
+            logEventInfo.Properties["ModuleName"] = ModuleName;
+            logEventInfo.Properties["Msg"] = Msg;
+            logEventInfo.Properties["TenantId"] = TenantId;
+            logEventInfo.Level = Level;
+            _logger.Log(logEventInfo);
+        }
+    }
+}

+ 8 - 0
MicroServices/Business/Business.Host/Business.Host.csproj

@@ -16,6 +16,8 @@
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>
     <PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="6.0.3" />
+    <PackageReference Include="NLog.Database" Version="5.1.2" />
+    <PackageReference Include="NLog.Web.AspNetCore" Version="5.2.2" />
     <PackageReference Include="Quartz.AspNetCore" Version="3.6.2" />
     <PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
     <PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
@@ -40,4 +42,10 @@
     <Folder Include="wwwroot\" />
   </ItemGroup>
 
+  <ItemGroup>
+    <Content Update="nlog.config">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+  </ItemGroup>
+
 </Project>

+ 20 - 1
MicroServices/Business/Business.Host/BusinessHostModule.cs

@@ -1,5 +1,6 @@
 using Autofac.Core;
 using Business.Core.MongoDBHelper;
+using Business.Core.Utilities;
 using Business.EntityFrameworkCore;
 using Business.MultiTenancy;
 using Business.Quartz;
@@ -11,8 +12,13 @@ using Microsoft.AspNetCore.Hosting;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
 using Microsoft.OpenApi.Models;
+using NLog;
+using NLog.Extensions.Logging;
+using NLog.Web;
 using Quartz;
+using Serilog.Events;
 using StackExchange.Redis;
 using System;
 using System.Collections.Generic;
@@ -93,11 +99,15 @@ namespace Business
 
         private void ConfigureQuartz(ServiceConfigurationContext context, IConfiguration configuration)
         {
+            //程序启动执行一次日志分表检查,可以自己初始化避免需要部署脚本
+            LogHostedService logHostedService = new LogHostedService();
+            logHostedService.LogInstall();
+
             context.Services.AddQuartz(q =>
             {
                 q.UseMicrosoftDependencyInjectionScopedJobFactory();
                 // Just use the name of your job that you created in the Jobs folder.
-                var jobKey = new JobKey("DemoJob");
+                var jobKey = new JobKey("SyncDataJob");
                 q.AddJob<SyncMySQLDataJob>(opts => opts.WithIdentity(jobKey));
 
                 q.AddTrigger(opts => opts
@@ -105,6 +115,15 @@ namespace Business
                     .WithIdentity("DemoJob-trigger")
                     .WithCronSchedule("0 45 11 * * ?")
                     .WithDescription("定时同步MySQL基础数据到MongoDB"));
+
+                var NLogJobKey = new JobKey("NLogJob");
+                q.AddJob<NLogJob>(opts => opts.WithIdentity(NLogJobKey));
+
+                q.AddTrigger(opts => opts
+                    .ForJob(NLogJobKey)
+                    .WithIdentity("DemoJob-trigger")
+                    .WithCronSchedule("0 0 0 * * ?")
+                    .WithDescription("定时创建NLog日志按月分表"));
             });
             context.Services.AddQuartzServer(options =>
             {

+ 7 - 2
MicroServices/Business/Business.Host/Program.cs

@@ -1,8 +1,10 @@
 using System;
 using System.IO;
+using Business.Core.MongoDBHelper;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Hosting;
+using NLog.Web;
 using Serilog;
 using Serilog.Events;
 using Serilog.Sinks.Elasticsearch;
@@ -18,6 +20,7 @@ namespace Business
                 .AddJsonFile("appsettings.json")
                 .AddEnvironmentVariables()
                 .Build();
+            NLog.Extensions.Logging.ConfigSettingLayoutRenderer.DefaultConfiguration = configuration;
 
             Log.Logger = new LoggerConfiguration()
 #if DEBUG
@@ -44,7 +47,8 @@ namespace Business
             }
             finally
             {
-                Log.CloseAndFlush();
+                //Log.CloseAndFlush();
+                NLog.LogManager.Shutdown();
             }
         }
 
@@ -55,6 +59,7 @@ namespace Business
                     webBuilder.UseStartup<Startup>();
                 })
                 .UseAutofac()
-                .UseSerilog();
+                //.UseSerilog()
+                .UseNLog();
     }
 }

+ 1 - 0
MicroServices/Business/Business.Host/appsettings.json

@@ -4,6 +4,7 @@
   },
   "ConnectionStrings": {
     "Default": "Server=123.60.180.165;Database=dopbiz;Uid=root; Pwd=5heng=uN;Allow User Variables=true",
+    "DOPLog": "Server=123.60.180.165;Database=doplog;Uid=root; Pwd=5heng=uN;Allow User Variables=true",
     "MongoDB": "mongodb://zzydop:h1Q$us3r@123.60.180.165/",
     "DBName": "dopbase"
   },

+ 73 - 0
MicroServices/Business/Business.Host/nlog.config

@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
+      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+      autoReload="true"
+	  throwExceptions="true"
+      internalLogLevel="Info"
+      internalLogFile="${basedir}/NLog/${date:format=yyyyMM}/Bussiness.txt">
+	<extensions>
+		<add assembly="NLog.Web.AspNetCore"/>
+	</extensions>
+	<!-- 定义变量当前应用程序名称 -->
+	<variable name="AppName" value="Bussiness" />
+	<!-- 日志输出目标 -->
+	<targets>
+		<!--把日志输出到控制台 -->
+		<target xsi:type="Console" name="lifetimeConsole" layout="${level:truncate=4:tolower=true}: ${logger}[0]${newline}      ${message}${exception:format=tostring}" />
+		<!-- 把日志记录到文件(通用) -->
+		<target xsi:type="File" name="allfile" fileName="${basedir}\..\Log\${date:format=yyyyMM}\${var:AppName}-all-${shortdate}.txt" encoding="UTF-8"
+            archiveFileName="${basedir}\..\Log\WMSAPI-all-${shortdate}.{#}.txt" archiveAboveSize="10485760"
+            layout="${longdate}|${event-properties:item=EventId_Id:whenEmpty=0}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />
+		<!--把日志输出到数据库 -->
+		<target xsi:type="Database" name="database" dbProvider="MySqlConnector.MySqlConnection, MySqlConnector" connectionString="${configsetting:item=ConnectionStrings.DOPLog}">
+			<install-command ignoreFailures="true">
+				<text>
+					<!-- NOTE: call LogManager.Configuration.Install(new InstallationContext()); to execute this query. -->
+					CREATE TABLE IF NOT EXISTS `Sys_Log${date:format=yyyyMM}`  (
+					`id` bigint NOT NULL AUTO_INCREMENT,
+					`createtime` datetime NOT NULL,
+					`appname` varchar(50) NOT NULL,
+					`modulename` varchar(50)  NULL,
+					`level` varchar(50) NOT NULL,
+					`logger` varchar(1024) NULL DEFAULT NULL,
+					`msg` text NULL,
+					`userid` varchar(50) NULL DEFAULT NULL,
+					`url` varchar(1024) NULL DEFAULT NULL,
+					`ip` varchar(255) NULL DEFAULT NULL,
+					`tenantId` varchar(50) NULL,
+					PRIMARY KEY (`id`) USING BTREE
+					);
+				</text>
+			</install-command>
+			<commandText>
+				INSERT INTO `Sys_Log${date:format=yyyyMM}`(`createtime`, `appname`, `modulename`, `level`, `logger`, `msg`,`userid`, `url`, `ip`,`tenantId`) VALUES (@CreateTime, @AppName,@ModuleName, @Level, @Logger, @Msg, @UserId, @Url, @IP,@TenantId);
+			</commandText>
+			<parameter name="@CreateTime" layout="${longdate}" />
+			<parameter name="@AppName" layout="${var:AppName}" />
+			<parameter name="@ModuleName" layout="${event-context:item=ModuleName}" allowDbNull="true"/>
+			<parameter name="@Level" layout="${level}" />
+			<parameter name="@Logger" layout="${logger}" allowDbNull="true" />
+			<parameter name="@Msg" layout="${event-context:item=Msg}" allowDbNull="true" />
+			<parameter name="@UserId" layout="${aspnet-user-claim:userId}" allowDbNull="true" />
+			<parameter name="@Url" layout="${aspnet-request-url}" allowDbNull="true" />
+			<parameter name="@IP" layout="${aspnet-request-ip}" allowDbNull="true" />
+            <parameter name="@TenantId" layout="${event-context:item=TenantId}" allowDbNull="true" />
+		</target>
+	</targets>
+
+	<!-- 日志输出规则 -->
+	<rules>
+		<!--All logs, including from Microsoft-->
+		<!--<logger name="*" minlevel="Trace" writeTo="allfile" />-->
+
+		<!--Output hosting lifetime messages to console target for faster startup detection -->
+		<logger name="Microsoft.Hosting.Lifetime" minlevel="Debug" writeTo="allfile,database" final="true" />
+		<logger name="Microsoft.EntityFrameworkCore.Model.Validation" maxlevel="Error" writeTo="allfile,database" final="true" />
+
+		<!--Skip non-critical Microsoft logs and so log only own logs (BlackHole) -->
+		<logger name="Microsoft.*" maxlevel="Info" final="true" />
+		<logger name="System.Net.Http.*" maxlevel="Info" final="true" />
+
+		<logger name="*" minlevel="Trace" writeTo="allfile,database" />
+	</rules>
+</nlog>

+ 4 - 1
MicroServices/Business/Business.HttpApi/Controllers/TestController.cs

@@ -1,4 +1,5 @@
-using Business.Test;
+using Business.Core.Utilities;
+using Business.Test;
 using Microsoft.AspNetCore.Mvc;
 using System.Collections.Generic;
 using System.Linq;
@@ -44,6 +45,8 @@ namespace Business.Controllers
         [Route("user-count")]
         public Task<long> GetUserCount()
         {
+            NLogHelper.Default.WriteLog("TestController", "默认logger","");
+            new NLogHelper("TestController").WriteLog("TestController", "自定义logger","");
             return _testAppService.GetUserCount();
         }
 

+ 3 - 3
MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/DigitalManufacturing.Application.Contracts.csproj

@@ -4,11 +4,11 @@
     <TargetFramework>net6.0</TargetFramework>
     <RootNamespace>DigitalManufacturing</RootNamespace>
     <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
-    <PackageId>XCZ.Procurement.Application.Contracts</PackageId>
+    <PackageId>XCZ.DigitalManufacturing.Application.Contracts</PackageId>
     <Version>0.1.1</Version>
     <Authors>XCZ</Authors>
-    <Product>Procurement</Product>
-    <Description>Procurement服务Application.Contracts远程依赖</Description>
+    <Product>DigitalManufacturing</Product>
+    <Description>DigitalManufacturing服务Application.Contracts远程依赖</Description>
     <PackageProjectUrl>https://github.com/WilliamXu96/ABP-MicroService</PackageProjectUrl>
     <RepositoryUrl>https://github.com/WilliamXu96/ABP-MicroService</RepositoryUrl>
   </PropertyGroup>

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/DigitalManufacturingApplicationContractsModule.cs

@@ -6,7 +6,7 @@ using Volo.Abp.PermissionManagement;
 using Volo.Abp.Validation.Localization;
 using Volo.Abp.VirtualFileSystem;
 
-namespace Procurement
+namespace DigitalManufacturing
 {
     [DependsOn(
        typeof(AbpLocalizationModule),

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/DigitalManufacturingManagement/Dto/FileInfoDto.cs

@@ -1,7 +1,7 @@
 using System;
 using Volo.Abp.Application.Dtos;
 
-namespace Procurement.FileManagement.Dto
+namespace DigitalManufacturing.FileManagement.Dto
 {
     public class FileInfoDto : EntityDto<Guid>
     {

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/DigitalManufacturingManagement/Dto/GetFileInputDto.cs

@@ -1,6 +1,6 @@
 using Volo.Abp.Application.Dtos;
 
-namespace Procurement.FileManagement.Dto
+namespace DigitalManufacturing.FileManagement.Dto
 {
     public class GetFileInputDto : PagedAndSortedResultRequestDto
     {

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/DigitalManufacturingManagement/IDigitalManufacturingAppService.cs

@@ -1,4 +1,4 @@
-using Procurement.FileManagement.Dto;
+using DigitalManufacturing.FileManagement.Dto;
 using Microsoft.AspNetCore.Http;
 using System.ComponentModel.DataAnnotations;
 using System.Threading.Tasks;

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/Permissions/DigitalManufacturingPermissionDefinitionProvider.cs

@@ -3,7 +3,7 @@ using Volo.Abp.Authorization.Permissions;
 using Volo.Abp.Localization;
 using Volo.Abp.MultiTenancy;
 
-namespace Procurement.Permissions
+namespace DigitalManufacturing.Permissions
 {
     public class DigitalManufacturingPermissionDefinitionProvider: PermissionDefinitionProvider
     {

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/Permissions/DigitalManufacturingPermissions.cs

@@ -1,4 +1,4 @@
-namespace Procurement.Permissions
+namespace DigitalManufacturing.Permissions
 {
     public static class DigitalManufacturingPermissions
     {

+ 4 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Application/DigitalManufacturing.Application.csproj

@@ -2,16 +2,19 @@
 
   <PropertyGroup>
     <TargetFramework>net6.0</TargetFramework>
-    <RootNamespace>Procurement</RootNamespace>
+    <RootNamespace>DigitalManufacturing</RootNamespace>
   </PropertyGroup>
 
   <ItemGroup>
+    <PackageReference Include="NLog" Version="5.1.2" />
+    <PackageReference Include="Quartz.AspNetCore" Version="3.6.2" />
     <PackageReference Include="Volo.Abp.AspNetCore.Mvc" Version="6.0.0" />
     <PackageReference Include="Volo.Abp.AutoMapper" Version="6.0.0" />
   </ItemGroup>
 
   <ItemGroup>
     <ProjectReference Include="..\DigitalManufacturing.Application.Contracts\DigitalManufacturing.Application.Contracts.csproj" />
+    <ProjectReference Include="..\DigitalManufacturing.Core\DigitalManufacturing.Core.csproj" />
     <ProjectReference Include="..\DigitalManufacturing.Domain\DigitalManufacturing.Domain.csproj" />
   </ItemGroup>
 

+ 3 - 3
MicroServices/DigitalManufacturing/DigitalManufacturing.Application/DigitalManufacturingApplicationAutoMapperProfile.cs

@@ -1,8 +1,8 @@
 using AutoMapper;
-using Procurement.FileManagement.Dto;
-using Procurement.Models;
+using DigitalManufacturing.FileManagement.Dto;
+using DigitalManufacturing.Models;
 
-namespace Procurement
+namespace DigitalManufacturing
 {
     public class DigitalManufacturingApplicationAutoMapperProfile : Profile
     {

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Application/DigitalManufacturingApplicationModule.cs

@@ -1,7 +1,7 @@
 using Volo.Abp.AutoMapper;
 using Volo.Abp.Modularity;
 
-namespace Procurement
+namespace DigitalManufacturing
 {
     [DependsOn(
         typeof(DigitalManufacturingDomainModule),

+ 13 - 6
MicroServices/DigitalManufacturing/DigitalManufacturing.Application/DigitalManufacturingManagement/DigitalManufacturingAppService.cs

@@ -1,6 +1,7 @@
-using Procurement.Enums;
-using Procurement.FileManagement.Dto;
-using Procurement.Models;
+using DigitalManufacturing.Core;
+using DigitalManufacturing.Enums;
+using DigitalManufacturing.FileManagement.Dto;
+using DigitalManufacturing.Models;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.EntityFrameworkCore;
@@ -14,21 +15,25 @@ using System.Threading.Tasks;
 using Volo.Abp;
 using Volo.Abp.Application.Dtos;
 using Volo.Abp.Application.Services;
+using Volo.Abp.DependencyInjection;
 using Volo.Abp.Domain.Repositories;
-using FileInfo = Procurement.Models.FileInfo;
+using Volo.Abp.MultiTenancy;
+using FileInfo = DigitalManufacturing.Models.FileInfo;
 
 namespace DigitalManufacturing.DigitalManufacturingManagement
 {
-    public class DigitalManufacturingAppService : ApplicationService, IDigitalManufacturingAppService
+    public class DigitalManufacturingAppService : ApplicationService, IDigitalManufacturingAppService, ITransientDependency
     {
+        private readonly ICurrentTenant _currentTenant;
         private readonly IRepository<FileInfo, Guid> _repository;
         private readonly FileManager _fileManager;
         string[] pictureFormatArray = { ".png", ".jpg", ".jpeg", ".gif", ".PNG", ".JPG", ".JPEG", ".GIF" };
 
-        public DigitalManufacturingAppService(IRepository<FileInfo, Guid> repository, FileManager fileManager)
+        public DigitalManufacturingAppService(IRepository<FileInfo, Guid> repository, FileManager fileManager, ICurrentTenant currentTenant)
         {
             _repository = repository;
             _fileManager = fileManager;
+            _currentTenant = currentTenant;
         }
 
         public async Task<PagedResultDto<FileInfoDto>> GetAll(GetFileInputDto input)
@@ -52,6 +57,8 @@ namespace DigitalManufacturing.DigitalManufacturingManagement
             //限制100M
             if (file.Length > 104857600)
             {
+                NLogHelper.Default.WriteLog("GetAll", "上传文件过大", _currentTenant.Id.ToString());
+                new NLogHelper("DigitalManufacturingAppService").WriteLog("GetAll", "自定义logger", _currentTenant.Id.ToString());
                 throw new BusinessException("上传文件过大");
             }
             //文件格式

+ 20 - 0
MicroServices/DigitalManufacturing/DigitalManufacturing.Application/Quartz/LogHostedService.cs

@@ -0,0 +1,20 @@
+using Microsoft.Extensions.Hosting;
+using NLog;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace DigitalManufacturing.Quartz
+{
+    //Nlog日志按月分表,需要每天凌晨检查是否存在表,不存在就要新建表,程序启动的时候也要检查一次。类似初始化
+    public class LogHostedService
+    {
+        public void LogInstall()
+        {
+            LogManager.Configuration.Install(new NLog.Config.InstallationContext());//每天0点执行一次
+        }
+    }
+}

+ 28 - 0
MicroServices/DigitalManufacturing/DigitalManufacturing.Application/Quartz/NLogJob.cs

@@ -0,0 +1,28 @@
+using Quartz;
+using System.Threading.Tasks;
+
+namespace DigitalManufacturing.Quartz
+{
+    public class NLogJob : IJob
+    {
+
+        /// <summary>
+        /// Nlog日志按月分表,需要每天凌晨检查是否存在表,不存在就要新建表,程序启动的时候也要检查一次。类似初始化
+        /// </summary>
+        public readonly LogHostedService _logHostedService;
+
+        /// <summary>
+        /// 构造函数
+        /// </summary>
+        public NLogJob(LogHostedService logHostedService)
+        {
+            _logHostedService = logHostedService;
+        }
+        public Task Execute(IJobExecutionContext context)
+        {
+            _logHostedService.LogInstall();
+
+            return Task.CompletedTask;
+        }
+    }
+}

+ 14 - 0
MicroServices/DigitalManufacturing/DigitalManufacturing.Core/DigitalManufacturing.Core.csproj

@@ -0,0 +1,14 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net6.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="NLog" Version="5.1.2" />
+    <PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" />
+  </ItemGroup>
+
+</Project>

+ 70 - 0
MicroServices/DigitalManufacturing/DigitalManufacturing.Core/NLogHelper.cs

@@ -0,0 +1,70 @@
+using NLog;
+
+namespace DigitalManufacturing.Core
+{
+    /// <summary>
+    /// Nlog日志帮助类
+    /// </summary>
+    public class NLogHelper
+    {
+        #region 初始化
+        readonly Logger _logger;
+
+        private NLogHelper(Logger logger)
+        {
+            this._logger = logger;
+        }
+
+        /// <summary>
+        /// 自定义Logger,否则用默认的GetCurrentClassLogger
+        /// </summary>
+        /// <param name="name"></param>
+        public NLogHelper(string name) : this(LogManager.GetLogger(name))
+        {
+        }
+
+        /// <summary>
+        /// 默认 ${logger} (Default 文件夹下)
+        /// </summary>
+        public static NLogHelper Default { get; private set; }
+        static NLogHelper()
+        {
+            Default = new NLogHelper(LogManager.GetCurrentClassLogger());
+        }
+        #endregion
+
+        /// <summary>
+        /// 日志写入,默认info等级
+        /// </summary>
+        /// <param name="ModuleName">模块名称</param>
+        /// <param name="Msg">日志内容</param>
+        /// <param name="TenantId">租户Id</param>
+        public void WriteLog(string ModuleName, string Msg, string TenantId = "")
+        {
+            LogEventInfo logEventInfo = new LogEventInfo();
+            logEventInfo.Properties["ModuleName"] = ModuleName;
+            logEventInfo.Properties["Msg"] = Msg;
+            logEventInfo.Properties["TenantId"] = TenantId;
+            logEventInfo.Level = LogLevel.Info;
+            _logger.Log(logEventInfo);
+        }
+
+        /// <summary>
+        /// 日志写入,自己传日志类别
+        /// </summary>
+        /// <param name="ModuleName">模块名称</param>
+        /// <param name="Msg">日志内容</param>
+        /// <param name="Level">日志级别</param>
+        /// <param name="TenantId">租户Id</param>
+        public void WriteLog(string ModuleName, string Msg, LogLevel Level, string TenantId = "")
+        {
+
+            LogEventInfo logEventInfo = new LogEventInfo();
+            logEventInfo.Properties["ModuleName"] = ModuleName;
+            logEventInfo.Properties["Msg"] = Msg;
+            logEventInfo.Properties["TenantId"] = TenantId;
+            logEventInfo.Level = Level;
+            _logger.Log(logEventInfo);
+        }
+    }
+}

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Domain/DigitalManufacturing.Domain.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <TargetFramework>net6.0</TargetFramework>
-    <RootNamespace>Procurement</RootNamespace>
+    <RootNamespace>DigitalManufacturing</RootNamespace>
   </PropertyGroup>
 
   <ItemGroup>

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Domain/DigitalManufacturingDomainModule.cs

@@ -1,7 +1,7 @@
 using Volo.Abp.Localization;
 using Volo.Abp.Modularity;
 
-namespace Procurement
+namespace DigitalManufacturing
 {
     [DependsOn(
         typeof(AbpLocalizationModule)

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Domain/Enums/Enums.cs

@@ -2,7 +2,7 @@
 using System.Collections.Generic;
 using System.Text;
 
-namespace Procurement.Enums
+namespace DigitalManufacturing.Enums
 {
     public enum FileType
     {

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.Domain/Models/FileInfo.cs

@@ -1,10 +1,10 @@
-using Procurement.Enums;
+using DigitalManufacturing.Enums;
 using System;
 using Volo.Abp;
 using Volo.Abp.Domain.Entities.Auditing;
 using Volo.Abp.MultiTenancy;
 
-namespace Procurement.Models
+namespace DigitalManufacturing.Models
 {
     public class FileInfo : AuditedAggregateRoot<Guid>, ISoftDelete, IMultiTenant
     {

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.Domain/Models/FileManager.cs

@@ -1,10 +1,10 @@
-using Procurement.Enums;
+using DigitalManufacturing.Enums;
 using System;
 using System.Threading.Tasks;
 using Volo.Abp.Domain.Repositories;
 using Volo.Abp.Domain.Services;
 
-namespace Procurement.Models
+namespace DigitalManufacturing.Models
 {
     public class FileManager : DomainService
     {

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.EntityFrameworkCore/DigitalManufacturing.EntityFrameworkCore.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <TargetFramework>net6.0</TargetFramework>
-    <RootNamespace>Procurement</RootNamespace>
+    <RootNamespace>DigitalManufacturing</RootNamespace>
   </PropertyGroup>
 
   <ItemGroup>

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.EntityFrameworkCore/EntityFrameworkCore/DigitalManufacturingDbContext.cs

@@ -1,4 +1,4 @@
-using Procurement.Models;
+using DigitalManufacturing.Models;
 using Microsoft.EntityFrameworkCore;
 using System;
 using System.Collections.Generic;
@@ -6,7 +6,7 @@ using System.Text;
 using Volo.Abp.Data;
 using Volo.Abp.EntityFrameworkCore;
 
-namespace Procurement.EntityFrameworkCore
+namespace DigitalManufacturing.EntityFrameworkCore
 {
     [ConnectionStringName("Default")]
     public class DigitalManufacturingDbContext : AbpDbContext<DigitalManufacturingDbContext>

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.EntityFrameworkCore/EntityFrameworkCore/DigitalManufacturingDbContextModelCreatingExtensions.cs

@@ -1,4 +1,4 @@
-using Procurement.Models;
+using DigitalManufacturing.Models;
 using Microsoft.EntityFrameworkCore;
 using System;
 using System.Collections.Generic;
@@ -6,7 +6,7 @@ using System.Text;
 using Volo.Abp;
 using Volo.Abp.EntityFrameworkCore.Modeling;
 
-namespace Procurement.EntityFrameworkCore
+namespace DigitalManufacturing.EntityFrameworkCore
 {
     public static class DigitalManufacturingDbContextModelCreatingExtensions
     {

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.EntityFrameworkCore/EntityFrameworkCore/DigitalManufacturingEntityFrameworkCoreModule.cs

@@ -3,7 +3,7 @@ using Volo.Abp.EntityFrameworkCore;
 using Volo.Abp.Modularity;
 using Volo.Abp.PermissionManagement.EntityFrameworkCore;
 
-namespace Procurement.EntityFrameworkCore
+namespace DigitalManufacturing.EntityFrameworkCore
 {
     [DependsOn(
         typeof(DigitalManufacturingDomainModule),

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/DOP/DOPController.cs

@@ -1,5 +1,5 @@
-using Procurement.Enums;
-using Procurement.Models;
+using DigitalManufacturing.Enums;
+using DigitalManufacturing.Models;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/HomeController.cs

@@ -1,7 +1,7 @@
 using Microsoft.AspNetCore.Mvc;
 using Volo.Abp.AspNetCore.Mvc;
 
-namespace Procurement.Controllers
+namespace DigitalManufacturing.Controllers
 {
     public class HomeController : AbpController
     {

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/Kanban/KanbanController.cs

@@ -1,5 +1,5 @@
-using Procurement.Enums;
-using Procurement.Models;
+using DigitalManufacturing.Enums;
+using DigitalManufacturing.Models;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/MES/MESController.cs

@@ -1,5 +1,5 @@
-using Procurement.Enums;
-using Procurement.Models;
+using DigitalManufacturing.Enums;
+using DigitalManufacturing.Models;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/QMS/QMSController.cs

@@ -1,5 +1,5 @@
-using Procurement.Enums;
-using Procurement.Models;
+using DigitalManufacturing.Enums;
+using DigitalManufacturing.Models;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/SIM/AndonController.cs

@@ -1,5 +1,5 @@
-using Procurement.Enums;
-using Procurement.Models;
+using DigitalManufacturing.Enums;
+using DigitalManufacturing.Models;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/SIM/SIMController.cs

@@ -1,5 +1,5 @@
-using Procurement.Enums;
-using Procurement.Models;
+using DigitalManufacturing.Enums;
+using DigitalManufacturing.Models;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/WMS/WMSController.cs

@@ -1,5 +1,5 @@
-using Procurement.Enums;
-using Procurement.Models;
+using DigitalManufacturing.Enums;
+using DigitalManufacturing.Models;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;

+ 10 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/DigitalManufacturing.Host.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <TargetFramework>net6.0</TargetFramework>
-    <RootNamespace>Procurement</RootNamespace>
+    <RootNamespace>DigitalManufacturing</RootNamespace>
   </PropertyGroup>
 
   <ItemGroup>
@@ -13,6 +13,9 @@
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>
     <PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="6.0.3" />
+    <PackageReference Include="NLog.Database" Version="5.1.2" />
+    <PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" />
+    <PackageReference Include="NLog.Web.AspNetCore" Version="5.2.2" />
     <PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
     <PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.0" />
@@ -33,4 +36,10 @@
     <Folder Include="wwwroot\Images\" />
   </ItemGroup>
 
+  <ItemGroup>
+    <Content Update="nlog.config">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+  </ItemGroup>
+
 </Project>

+ 36 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/DigitalManufacturingHostModule.cs

@@ -1,4 +1,4 @@
-using Procurement.EntityFrameworkCore;
+using DigitalManufacturing.EntityFrameworkCore;
 using Microsoft.AspNetCore.Authentication.JwtBearer;
 using Microsoft.AspNetCore.Builder;
 using Microsoft.AspNetCore.Cors;
@@ -25,8 +25,10 @@ using Volo.Abp.Modularity;
 using Volo.Abp.MultiTenancy;
 using Volo.Abp.Threading;
 using Volo.Abp.VirtualFileSystem;
+using DigitalManufacturing.Quartz;
+using Quartz;
 
-namespace Procurement
+namespace DigitalManufacturing
 {
     [DependsOn(
         typeof(AbpAutofacModule),
@@ -55,6 +57,38 @@ namespace Procurement
             ConfigureCors(context, configuration);
             //ConfigureRedis(context, configuration, hostingEnvironment);
             ConfigureSwaggerServices(context);
+            ConfigureQuartz(context, configuration);
+        }
+
+        private void ConfigureQuartz(ServiceConfigurationContext context, IConfiguration configuration)
+        {
+            //程序启动执行一次日志分表检查,可以自己初始化避免需要部署脚本
+            LogHostedService logHostedService = new LogHostedService();
+            logHostedService.LogInstall();
+
+            context.Services.AddQuartz(q =>
+            {
+                q.UseMicrosoftDependencyInjectionScopedJobFactory();
+    
+                var NLogJobKey = new JobKey("NLogJob");
+                q.AddJob<NLogJob>(opts => opts.WithIdentity(NLogJobKey));
+
+                q.AddTrigger(opts => opts
+                    .ForJob(NLogJobKey)
+                    .WithIdentity("DemoJob-trigger")
+                    .WithCronSchedule("0 0 0 * * ?")
+                    .WithDescription("定时创建NLog日志按月分表"));
+            });
+            context.Services.AddQuartzServer(options =>
+            {
+                // when shutting down we want jobs to complete gracefully
+                options.WaitForJobsToComplete = true;
+            });
+            //context.Services.AddQuartzHostedService(options =>
+            //{
+            //    // when shutting down we want jobs to complete gracefully
+            //    options.WaitForJobsToComplete = true;
+            //});
         }
 
         private void ConfigureConventionalControllers()

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/EntityFrameworkCore/DigitalManufacturingMigrationDbContext.cs

@@ -5,7 +5,7 @@ using System.Linq;
 using System.Threading.Tasks;
 using Volo.Abp.EntityFrameworkCore;
 
-namespace Procurement.EntityFrameworkCore
+namespace DigitalManufacturing.EntityFrameworkCore
 {
     public class DigitalManufacturingMigrationDbContext : AbpDbContext<DigitalManufacturingMigrationDbContext>
     {

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/EntityFrameworkCore/DigitalManufacturingMigrationDbContextFactory.cs

@@ -7,7 +7,7 @@ using System.IO;
 using System.Linq;
 using System.Threading.Tasks;
 
-namespace Procurement.EntityFrameworkCore
+namespace DigitalManufacturing.EntityFrameworkCore
 {
     public class DigitalManufacturingMigrationDbContextFactory : IDesignTimeDbContextFactory<DigitalManufacturingMigrationDbContext>
     {

+ 7 - 4
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Program.cs

@@ -3,10 +3,11 @@ using System.IO;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Hosting;
+using NLog.Web;
 using Serilog;
 using Serilog.Events;
 
-namespace Procurement
+namespace DigitalManufacturing
 {
     public class Program
     {
@@ -17,7 +18,7 @@ namespace Procurement
                 .AddJsonFile("appsettings.json")
                 .AddEnvironmentVariables()
                 .Build();
-
+            NLog.Extensions.Logging.ConfigSettingLayoutRenderer.DefaultConfiguration = configuration;
             Log.Logger = new LoggerConfiguration()
 #if DEBUG
                 .MinimumLevel.Debug()
@@ -32,7 +33,7 @@ namespace Procurement
 
             try
             {
-                Log.Information("Starting Procurement.Host");
+                Log.Information("Starting DigitalManufacturing.Host");
                 CreateHostBuilder(args).Build().Run();
                 return 0;
             }
@@ -44,6 +45,7 @@ namespace Procurement
             finally
             {
                 Log.CloseAndFlush();
+                NLog.LogManager.Shutdown();
             }
         }
 
@@ -54,6 +56,7 @@ namespace Procurement
                     webBuilder.UseStartup<Startup>();
                 })
                 .UseAutofac()
-                .UseSerilog();
+                .UseSerilog()
+                .UseNLog();
     }
 }

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Startup.cs

@@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Hosting;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Logging;
 
-namespace Procurement
+namespace DigitalManufacturing
 {
     public class Startup
     {

+ 2 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/appsettings.json

@@ -3,7 +3,8 @@
     "CorsOrigins": "http://localhost:9527"
   },
   "ConnectionStrings": {
-    "Default": "Server=123.60.180.165;Database=dopbiz;Uid=root; Pwd=5heng=uN;Allow User Variables=True;sslMode=None;"
+    "Default": "Server=123.60.180.165;Database=dopbiz;Uid=root; Pwd=5heng=uN;Allow User Variables=True;sslMode=None;",
+    "DOPLog": "Server=123.60.180.165;Database=doplog;Uid=root; Pwd=5heng=uN;Allow User Variables=true"
   },
   "Redis": {
     "Configuration": "192.168.1.191"

+ 69 - 0
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/nlog.config

@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
+      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+      autoReload="true"
+	  throwExceptions="true"
+      internalLogLevel="Info"
+      internalLogFile="${basedir}/NLog/${date:format=yyyyMM}/Bussiness.txt">
+	<extensions>
+		<add assembly="NLog.Web.AspNetCore"/>
+	</extensions>
+	<!-- 定义变量当前应用程序名称 -->
+	<variable name="AppName" value="Bussiness" />
+	<!-- 日志输出目标 -->
+	<targets>
+		<!--把日志输出到控制台 -->
+		<target xsi:type="Console" name="lifetimeConsole" layout="${level:truncate=4:tolower=true}: ${logger}[0]${newline}      ${message}${exception:format=tostring}" />
+		<!--把日志输出到数据库 -->
+		<target xsi:type="Database" name="database" dbProvider="MySqlConnector.MySqlConnection, MySqlConnector" connectionString="${configsetting:item=ConnectionStrings.DOPLog}">
+			<install-command ignoreFailures="true">
+				<text>
+					<!-- NOTE: call LogManager.Configuration.Install(new InstallationContext()); to execute this query. -->
+					CREATE TABLE IF NOT EXISTS `Sys_Log${date:format=yyyyMM}`  (
+					`id` bigint NOT NULL AUTO_INCREMENT,
+					`createtime` datetime NOT NULL,
+					`appname` varchar(50) NOT NULL,
+					`modulename` varchar(50)  NULL,
+					`level` varchar(50) NOT NULL,
+					`logger` varchar(1024) NULL DEFAULT NULL,
+					`msg` text NULL,
+					`userid` varchar(50) NULL DEFAULT NULL,
+					`url` varchar(1024) NULL DEFAULT NULL,
+					`ip` varchar(255) NULL DEFAULT NULL,
+					`tenantId` varchar(50) NULL,
+					PRIMARY KEY (`id`) USING BTREE
+					);
+				</text>
+			</install-command>
+			<commandText>
+				INSERT INTO `Sys_Log${date:format=yyyyMM}`(`createtime`, `appname`, `modulename`, `level`, `logger`, `msg`,`userid`, `url`, `ip`,`tenantId`) VALUES (@CreateTime, @AppName,@ModuleName, @Level, @Logger, @Msg, @UserId, @Url, @IP,@TenantId);
+			</commandText>
+			<parameter name="@CreateTime" layout="${longdate}" />
+			<parameter name="@AppName" layout="${var:AppName}" />
+			<parameter name="@ModuleName" layout="${event-context:item=ModuleName}" allowDbNull="true"/>
+			<parameter name="@Level" layout="${level}" />
+			<parameter name="@Logger" layout="${logger}" allowDbNull="true" />
+			<parameter name="@Msg" layout="${event-context:item=Msg}" allowDbNull="true" />
+			<parameter name="@UserId" layout="${aspnet-user-claim:userId}" allowDbNull="true" />
+			<parameter name="@Url" layout="${aspnet-request-url}" allowDbNull="true" />
+			<parameter name="@IP" layout="${aspnet-request-ip}" allowDbNull="true" />
+            <parameter name="@TenantId" layout="${event-context:item=TenantId}" allowDbNull="true" />
+		</target>
+	</targets>
+
+	<!-- 日志输出规则 -->
+	<rules>
+		<!--All logs, including from Microsoft-->
+		<!--<logger name="*" minlevel="Trace" writeTo="allfile" />-->
+
+		<!--Output hosting lifetime messages to console target for faster startup detection -->
+		<logger name="Microsoft.Hosting.Lifetime" minlevel="Info" writeTo="lifetimeConsole,database" final="true" />
+		<logger name="Microsoft.EntityFrameworkCore.Model.Validation" maxlevel="Error" final="true" />
+
+		<!--Skip non-critical Microsoft logs and so log only own logs (BlackHole) -->
+		<logger name="Microsoft.*" maxlevel="Info" final="true" />
+		<logger name="System.Net.Http.*" maxlevel="Info" final="true" />
+
+		<logger name="*" minlevel="Trace" writeTo="lifetimeConsole,database" />
+	</rules>
+</nlog>

+ 6 - 0
MicroServices/DigitalManufacturing/DigitalManufacturing.sln

@@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DigitalManufacturing.Applic
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DigitalManufacturing.EntityFrameworkCore", "DigitalManufacturing.EntityFrameworkCore\DigitalManufacturing.EntityFrameworkCore.csproj", "{1938B13A-4806-487A-A374-1C66D750F133}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigitalManufacturing.Core", "DigitalManufacturing.Core\DigitalManufacturing.Core.csproj", "{596E8B63-69DC-4AA9-B644-512F3E85DACE}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -39,6 +41,10 @@ Global
 		{1938B13A-4806-487A-A374-1C66D750F133}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{1938B13A-4806-487A-A374-1C66D750F133}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{1938B13A-4806-487A-A374-1C66D750F133}.Release|Any CPU.Build.0 = Release|Any CPU
+		{596E8B63-69DC-4AA9-B644-512F3E85DACE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{596E8B63-69DC-4AA9-B644-512F3E85DACE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{596E8B63-69DC-4AA9-B644-512F3E85DACE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{596E8B63-69DC-4AA9-B644-512F3E85DACE}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 3 - 0
MicroServices/Procurement/Procurement.Application/Procurement.Application.csproj

@@ -6,12 +6,15 @@
   </PropertyGroup>
 
   <ItemGroup>
+    <PackageReference Include="NLog" Version="5.1.2" />
+    <PackageReference Include="Quartz.AspNetCore" Version="3.6.2" />
     <PackageReference Include="Volo.Abp.AspNetCore.Mvc" Version="6.0.0" />
     <PackageReference Include="Volo.Abp.AutoMapper" Version="6.0.0" />
   </ItemGroup>
 
   <ItemGroup>
     <ProjectReference Include="..\Procurement.Application.Contracts\Procurement.Application.Contracts.csproj" />
+    <ProjectReference Include="..\Procurement.Core\Procurement.Core.csproj" />
     <ProjectReference Include="..\Procurement.Domain\Procurement.Domain.csproj" />
   </ItemGroup>
 

+ 7 - 1
MicroServices/Procurement/Procurement.Application/ProcurementManagement/ProcurementAppService.cs

@@ -16,19 +16,23 @@ using Volo.Abp.Application.Dtos;
 using Volo.Abp.Application.Services;
 using Volo.Abp.Domain.Repositories;
 using FileInfo = Procurement.Models.FileInfo;
+using Volo.Abp.MultiTenancy;
+using Procurement.Core;
 
 namespace Procurement.FileManagement
 {
     public class ProcurementAppService : ApplicationService, IProcurementAppService
     {
+        private readonly ICurrentTenant _currentTenant;
         private readonly IRepository<FileInfo, Guid> _repository;
         private readonly FileManager _fileManager;
         string[] pictureFormatArray = { ".png", ".jpg", ".jpeg", ".gif", ".PNG", ".JPG", ".JPEG", ".GIF" };
 
-        public ProcurementAppService(IRepository<FileInfo, Guid> repository, FileManager fileManager)
+        public ProcurementAppService(IRepository<FileInfo, Guid> repository, FileManager fileManager, ICurrentTenant currentTenant)
         {
             _repository = repository;
             _fileManager = fileManager;
+            _currentTenant = currentTenant;
         }
 
         public async Task<PagedResultDto<FileInfoDto>> GetAll(GetFileInputDto input)
@@ -52,6 +56,8 @@ namespace Procurement.FileManagement
             //限制100M
             if (file.Length > 104857600)
             {
+                new NLogHelper("ProcurementAppService").WriteLog("Upload", "上传文件过大",NLog.LogLevel.Error,_currentTenant.Id.ToString());
+                NLogHelper.Default.WriteLog("Upload", "上传文件过大", _currentTenant.Id.ToString());
                 throw new BusinessException("上传文件过大");
             }
             //文件格式

+ 20 - 0
MicroServices/Procurement/Procurement.Application/Quartz/LogHostedService.cs

@@ -0,0 +1,20 @@
+using Microsoft.Extensions.Hosting;
+using NLog;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Procurement.Quartz
+{
+    //Nlog日志按月分表,需要每天凌晨检查是否存在表,不存在就要新建表,程序启动的时候也要检查一次。类似初始化
+    public class LogHostedService
+    {
+        public void LogInstall()
+        {
+            LogManager.Configuration.Install(new NLog.Config.InstallationContext());//每天0点执行一次
+        }
+    }
+}

+ 28 - 0
MicroServices/Procurement/Procurement.Application/Quartz/NLogJob.cs

@@ -0,0 +1,28 @@
+using Quartz;
+using System.Threading.Tasks;
+
+namespace Procurement.Quartz
+{
+    public class NLogJob : IJob
+    {
+
+        /// <summary>
+        /// Nlog日志按月分表,需要每天凌晨检查是否存在表,不存在就要新建表,程序启动的时候也要检查一次。类似初始化
+        /// </summary>
+        public readonly LogHostedService _logHostedService;
+
+        /// <summary>
+        /// 构造函数
+        /// </summary>
+        public NLogJob(LogHostedService logHostedService)
+        {
+            _logHostedService = logHostedService;
+        }
+        public Task Execute(IJobExecutionContext context)
+        {
+            _logHostedService.LogInstall();
+
+            return Task.CompletedTask;
+        }
+    }
+}

+ 70 - 0
MicroServices/Procurement/Procurement.Core/NLogHelper.cs

@@ -0,0 +1,70 @@
+using NLog;
+
+namespace Procurement.Core
+{
+    /// <summary>
+    /// Nlog日志帮助类
+    /// </summary>
+    public class NLogHelper
+    {
+        #region 初始化
+        readonly Logger _logger;
+
+        private NLogHelper(Logger logger)
+        {
+            this._logger = logger;
+        }
+
+        /// <summary>
+        /// 自定义Logger,否则用默认的GetCurrentClassLogger
+        /// </summary>
+        /// <param name="name"></param>
+        public NLogHelper(string name) : this(LogManager.GetLogger(name))
+        {
+        }
+
+        /// <summary>
+        /// 默认 ${logger} (Default 文件夹下)
+        /// </summary>
+        public static NLogHelper Default { get; private set; }
+        static NLogHelper()
+        {
+            Default = new NLogHelper(LogManager.GetCurrentClassLogger());
+        }
+        #endregion
+
+        /// <summary>
+        /// 日志写入,默认info等级
+        /// </summary>
+        /// <param name="ModuleName">模块名称</param>
+        /// <param name="Msg">日志内容</param>
+        /// <param name="TenantId">租户Id</param>
+        public void WriteLog(string ModuleName,string Msg,string TenantId="")
+        {
+            LogEventInfo logEventInfo=new LogEventInfo();
+            logEventInfo.Properties["ModuleName"] = ModuleName;
+            logEventInfo.Properties["Msg"] = Msg;
+            logEventInfo.Properties["TenantId"] = TenantId;
+            logEventInfo.Level = LogLevel.Info;
+            _logger.Log(logEventInfo);
+        }
+
+        /// <summary>
+        /// 日志写入,自己传日志类别
+        /// </summary>
+        /// <param name="ModuleName">模块名称</param>
+        /// <param name="Msg">日志内容</param>
+        /// <param name="Level">日志级别</param>
+        /// <param name="TenantId">租户Id</param>
+        public void WriteLog(string ModuleName, string Msg,LogLevel Level, string TenantId = "")
+        {
+            
+            LogEventInfo logEventInfo = new LogEventInfo();
+            logEventInfo.Properties["ModuleName"] = ModuleName;
+            logEventInfo.Properties["Msg"] = Msg;
+            logEventInfo.Properties["TenantId"] = TenantId;
+            logEventInfo.Level = Level;
+            _logger.Log(logEventInfo);
+        }
+    }
+}

+ 15 - 0
MicroServices/Procurement/Procurement.Core/Procurement.Core.csproj

@@ -0,0 +1,15 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net6.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="NLog" Version="5.1.2" />
+    <PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" />
+    <PackageReference Include="NLog.Web.AspNetCore" Version="5.2.2" />
+  </ItemGroup>
+
+</Project>

+ 2 - 0
MicroServices/Procurement/Procurement.Host/Procurement.Host.csproj

@@ -13,6 +13,8 @@
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>
     <PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="6.0.3" />
+    <PackageReference Include="NLog.Database" Version="5.1.2" />
+    <PackageReference Include="NLog.Web.AspNetCore" Version="5.2.2" />
     <PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
     <PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.0" />

+ 34 - 0
MicroServices/Procurement/Procurement.Host/ProcurementHostModule.cs

@@ -25,6 +25,8 @@ using Volo.Abp.Modularity;
 using Volo.Abp.MultiTenancy;
 using Volo.Abp.Threading;
 using Volo.Abp.VirtualFileSystem;
+using Procurement.Quartz;
+using Quartz;
 
 namespace Procurement
 {
@@ -55,6 +57,7 @@ namespace Procurement
             ConfigureCors(context, configuration);
             //ConfigureRedis(context, configuration, hostingEnvironment);
             ConfigureSwaggerServices(context);
+            ConfigureQuartz(context, configuration);
         }
 
         private void ConfigureConventionalControllers()
@@ -142,6 +145,37 @@ namespace Procurement
                 });
         }
 
+        private void ConfigureQuartz(ServiceConfigurationContext context, IConfiguration configuration)
+        {
+            //程序启动执行一次日志分表检查,可以自己初始化避免需要部署脚本
+            LogHostedService logHostedService = new LogHostedService();
+            logHostedService.LogInstall();
+
+            context.Services.AddQuartz(q =>
+            {
+                q.UseMicrosoftDependencyInjectionScopedJobFactory();
+  
+                var NLogJobKey = new JobKey("NLogJob");
+                q.AddJob<NLogJob>(opts => opts.WithIdentity(NLogJobKey));
+
+                q.AddTrigger(opts => opts
+                    .ForJob(NLogJobKey)
+                    .WithIdentity("DemoJob-trigger")
+                    .WithCronSchedule("0 0 0 * * ?")
+                    .WithDescription("定时创建NLog日志按月分表"));
+            });
+            context.Services.AddQuartzServer(options =>
+            {
+                // when shutting down we want jobs to complete gracefully
+                options.WaitForJobsToComplete = true;
+            });
+            //context.Services.AddQuartzHostedService(options =>
+            //{
+            //    // when shutting down we want jobs to complete gracefully
+            //    options.WaitForJobsToComplete = true;
+            //});
+        }
+
         private void ConfigureLocalization()
         {
             Configure<AbpLocalizationOptions>(options =>

+ 2 - 1
MicroServices/Procurement/Procurement.Host/Program.cs

@@ -17,7 +17,7 @@ namespace Procurement
                 .AddJsonFile("appsettings.json")
                 .AddEnvironmentVariables()
                 .Build();
-
+            NLog.Extensions.Logging.ConfigSettingLayoutRenderer.DefaultConfiguration = configuration;
             Log.Logger = new LoggerConfiguration()
 #if DEBUG
                 .MinimumLevel.Debug()
@@ -44,6 +44,7 @@ namespace Procurement
             finally
             {
                 Log.CloseAndFlush();
+                NLog.LogManager.Shutdown();
             }
         }
 

+ 69 - 0
MicroServices/Procurement/Procurement.Host/nlog.config

@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
+      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+      autoReload="true"
+	  throwExceptions="true"
+      internalLogLevel="Info"
+      internalLogFile="${basedir}/NLog/${date:format=yyyyMM}/Procurement.txt">
+	<extensions>
+		<add assembly="NLog.Web.AspNetCore"/>
+	</extensions>
+	<!-- 定义变量当前应用程序名称 -->
+	<variable name="AppName" value="Procurement" />
+	<!-- 日志输出目标 -->
+	<targets>
+		<!--把日志输出到控制台 -->
+		<target xsi:type="Console" name="lifetimeConsole" layout="${level:truncate=4:tolower=true}: ${logger}[0]${newline}      ${message}${exception:format=tostring}" />
+		<!--把日志输出到数据库 -->
+		<target xsi:type="Database" name="database" dbProvider="MySqlConnector.MySqlConnection, MySqlConnector" connectionString="${configsetting:item=ConnectionStrings.DOPLog}">
+			<install-command ignoreFailures="true">
+				<text>
+					<!-- NOTE: call LogManager.Configuration.Install(new InstallationContext()); to execute this query. -->
+					CREATE TABLE IF NOT EXISTS `Sys_Log${date:format=yyyyMM}`  (
+					`id` bigint NOT NULL AUTO_INCREMENT,
+					`createtime` datetime NOT NULL,
+					`appname` varchar(50) NOT NULL,
+					`modulename` varchar(50)  NULL,
+					`level` varchar(50) NOT NULL,
+					`logger` varchar(1024) NULL DEFAULT NULL,
+					`msg` text NULL,
+					`userid` varchar(50) NULL DEFAULT NULL,
+					`url` varchar(1024) NULL DEFAULT NULL,
+					`ip` varchar(255) NULL DEFAULT NULL,
+					`tenantId` varchar(50) NULL,
+					PRIMARY KEY (`id`) USING BTREE
+					);
+				</text>
+			</install-command>
+			<commandText>
+				INSERT INTO `Sys_Log${date:format=yyyyMM}`(`createtime`, `appname`, `modulename`, `level`, `logger`, `msg`,`userid`, `url`, `ip`,`tenantId`) VALUES (@CreateTime, @AppName,@ModuleName, @Level, @Logger, @Msg, @UserId, @Url, @IP,@TenantId);
+			</commandText>
+			<parameter name="@CreateTime" layout="${longdate}" />
+			<parameter name="@AppName" layout="${var:AppName}" />
+			<parameter name="@ModuleName" layout="${event-context:item=ModuleName}" allowDbNull="true"/>
+			<parameter name="@Level" layout="${level}" />
+			<parameter name="@Logger" layout="${logger}" allowDbNull="true" />
+			<parameter name="@Msg" layout="${event-context:item=Msg}" allowDbNull="true" />
+			<parameter name="@UserId" layout="${aspnet-user-claim:userId}" allowDbNull="true" />
+			<parameter name="@Url" layout="${aspnet-request-url}" allowDbNull="true" />
+			<parameter name="@IP" layout="${aspnet-request-ip}" allowDbNull="true" />
+            <parameter name="@TenantId" layout="${event-context:item=TenantId}" allowDbNull="true" />
+		</target>
+	</targets>
+
+	<!-- 日志输出规则 -->
+	<rules>
+		<!--All logs, including from Microsoft-->
+		<!--<logger name="*" minlevel="Trace" writeTo="allfile" />-->
+
+		<!--Output hosting lifetime messages to console target for faster startup detection -->
+		<logger name="Microsoft.Hosting.Lifetime" minlevel="Info" writeTo="lifetimeConsole,database" final="true" />
+		<logger name="Microsoft.EntityFrameworkCore.Model.Validation" maxlevel="Error" final="true" />
+
+		<!--Skip non-critical Microsoft logs and so log only own logs (BlackHole) -->
+		<logger name="Microsoft.*" maxlevel="Info" final="true" />
+		<logger name="System.Net.Http.*" maxlevel="Info" final="true" />
+
+		<logger name="*" minlevel="Trace" writeTo="lifetimeConsole,database" />
+	</rules>
+</nlog>

+ 6 - 0
MicroServices/Procurement/Procurement.sln

@@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Procurement.Application", "
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Procurement.EntityFrameworkCore", "Procurement.EntityFrameworkCore\Procurement.EntityFrameworkCore.csproj", "{1938B13A-4806-487A-A374-1C66D750F133}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Procurement.Core", "Procurement.Core\Procurement.Core.csproj", "{604C3CC6-AEDF-433F-8DDC-630E0B0552AF}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -39,6 +41,10 @@ Global
 		{1938B13A-4806-487A-A374-1C66D750F133}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{1938B13A-4806-487A-A374-1C66D750F133}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{1938B13A-4806-487A-A374-1C66D750F133}.Release|Any CPU.Build.0 = Release|Any CPU
+		{604C3CC6-AEDF-433F-8DDC-630E0B0552AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{604C3CC6-AEDF-433F-8DDC-630E0B0552AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{604C3CC6-AEDF-433F-8DDC-630E0B0552AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{604C3CC6-AEDF-433F-8DDC-630E0B0552AF}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE