Ver Fonte

nlog调整

Murphy há 2 anos atrás
pai
commit
e1b15ab86c

+ 5 - 0
.gitignore

@@ -2123,3 +2123,8 @@ MicroServices/Business/Bussiness.MongoModel/bin/Debug/net6.0/Business.MongoModel
 /MicroServices/Procurement/Procurement.Host/obj/Release
 /MicroServices/Procurement/Procurement.Host/bin/Release/net6.0
 /MicroServices/Procurement/.vs/Procurement/FileContentIndex
+/MicroServices/Business/Bussiness.Model/bin/Release/net6.0
+/MicroServices/Business/Bussiness.Model/obj/Release/net6.0
+/MicroServices/Business/Bussiness.MongoModel/bin/Release/net6.0
+/MicroServices/Business/Bussiness.EntityFrameworkCore.Test/obj/Release/net6.0
+/MicroServices/Business/Bussiness.Domain.Test/bin/Release/net6.0

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

@@ -38,7 +38,7 @@
       "Scope": "InternalGateway BaseService"
     }
   },
-  "UseSwagger": "false",
+  "UseSwagger": "true",
   "Hangfire": {
     "Login": "admin",
     "Password": "abc123"

+ 43 - 2
MicroServices/Procurement/Procurement.Host/nlog.config

@@ -14,11 +14,15 @@
 	<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="${gdc:item=appbasepath}\logs\nlog-${shortdate}.log" encoding="UTF-8"
+            archiveFileName="${gdc:item=appbasepath}\logs\nlog-${shortdate}.{#}.log" 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}">
+		<!--<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. -->
+					--><!-- 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,
@@ -48,6 +52,43 @@
 			<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>-->
+		<target xsi:type="Database" name="database" dbProvider="Microsoft.Data.SqlClient.SqlConnection, Microsoft.Data.SqlClient" connectionString="${configsetting:item=ConnectionStrings.DOPLog}">
+			<install-command ignoreFailures="true">
+				<text>
+					<!-- NOTE: call LogManager.Configuration.Install(new InstallationContext()); to execute this query. -->
+					if not exists (select * from sysobjects where id = object_id('dbo.Sys_Log${date:format=yyyyMM}')
+					and OBJECTPROPERTY(id, 'IsUserTable') = 1)
+					create table dbo.Sys_Log${date:format=yyyyMM}
+					(
+					id bigint identity(1,1) not null,
+					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,
+					CONSTRAINT [PK_dbo.Sys_Log${date:format=yyyyMM}] PRIMARY KEY CLUSTERED ([id] ASC) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
+					)
+				</text>
+			</install-command>
+			<commandText>
+				INSERT INTO dbo.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="${date}" />
+			<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>