SQL logging bij fout in proceslog

PHOTO EMBED

Mon Mar 08 2021 08:11:47 GMT+0000 (Coordinated Universal Time)

Saved by @Robbert

USE [Synergy]
GO

/****** Object:  Trigger [dbo].[ConsNobTrRaiseErrorProcessLog]    Script Date: 27-11-2019 21:27:23 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TRIGGER [dbo].[ConsNobTrRaiseErrorProcessLog] 
   ON  [dbo].[BacoProcessLog]
   AFTER INSERT
AS 
BEGIN

SET NOCOUNT ON;

DECLARE @CommandLine as NVARCHAR(500)
DECLARE @Message as NVARCHAR(2048)


SELECT @CommandLine = inserted.CommandLine, @Message = LEFT(CONCAT(N'Background process ',inserted.ProcessName,N' reported the following error: 

',inserted.LogText,N'
 
Additional information:
 
Background process: ',inserted.ProcessName,N' 
Command Line: ',inserted.CommandLine,N'
Server: ',inserted.Server,N'
Database: ',DB_NAME(),N' (',@@SERVERNAME,N')
Table: dbo.BacoProcessLog
Log Date: ',convert(nvarchar(20),inserted.LogDate,121),N'
Log ID: ',cast(inserted.LogID as nvarchar(50)),N'
Application: '+APP_NAME(),N'
SPID: '+cast(@@SPID as nvarchar(50)),N'
System user: '+SYSTEM_USER
),2048) 

FROM inserted 
WHERE inserted.LogType = 3 and inserted.LogText is not null

IF @CommandLine is not null --AND (@CommandLine like '%AR0030%' or @CommandLine like '%FACT03%') 
BEGIN
RAISERROR (@Message,16,1) WITH LOG;
END

END

GO

ALTER TABLE [dbo].[BacoProcessLog] ENABLE TRIGGER [ConsNobTrRaiseErrorProcessLog]
GO
content_copyCOPY