Are SQL sev 19-24 events logged to Windows Application event log?

David C 191 Reputation points
2020-11-16T21:12:32.24+00:00

I know that low severity DB Engine events (<19) are logged to the Windows Application event log, and only if the event_is_logged attribute is set to '1'.

From this article...

https://learn.microsoft.com/en-us/sql/relational-databases/errors-events/database-engine-error-severities?view=sql-server-ver15

...it says that "Error messages with a severity level from 19 through 25 are written to the error log."

So are high severity events 19 - 25 also logged to the Application event log, or only to the SQL Server error log?

Thanks.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,673 questions
0 comments No comments
{count} votes

Accepted answer
  1. m 4,271 Reputation points
    2020-11-17T10:58:29.293+00:00

    Hi @David C ,

    May I ask how you tested to put a severity 19+ event in the event log?

    You need to use sp_addmessage, and [ @with_log = ] { 'TRUE' | 'FALSE' } Is whether the message is to be written to the Windows application log when it occurs.

    Test code on my side as next:

    use testpowerapps  
    go  
      
    create TABLE TStudent (   
      StudentID varchar(10) NOT NULL,   
      Sname varchar(10) DEFAULT NULL,   
      sex varchar(4) DEFAULT NULL,   
      cardID varchar(20) DEFAULT NULL,   
      Birthday datetime DEFAULT NULL,   
      Email varchar(40) DEFAULT NULL,   
      Class varchar(20) DEFAULT NULL,   
      enterTime datetime DEFAULT NULL   
     )   
    go  
      
    create trigger insert_TStudent on TStudent for insert   
    as  
    declare @sum int  
    select @sum=count(StudentID) from TStudent where StudentID in (select StudentID from inserted)  
    if @sum>1  
    begin  
    raiserror(999999,21,1) with log  
    rollback tran   
    end  
      
    insert TStudent (StudentID,Sname,sex) values ('1','A','W')  
      
    --check 1  
    SELECT * FROM sysmessages  
      
    --sp_addmessage   
    USE master;    
    GO    
    EXEC sp_addmessage @msgnum=999999, @severity=21,@msgtext=N'The StudentID is already exists', @with_log='true'  
    GO    
      
    --check 2  
    SELECT * FROM sysmessages  
      
    --test, insert one duplicated id  
    use testpowerapps  
    go  
    insert TStudent (StudentID,Sname,sex) values ('1','A','W')  
    

    --SSMS error message
    40366-20201117errormessage.png

    --sqlserver error log
    40306-2020117sqlservererrorlog.png

    --Windows Applicatin Error
    40367-20201117applicationlog.png

    BR,
    Mia


    If the answer is helpful, please click "Accept Answer" and upvote it.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Erland Sommarskog 110.2K Reputation points
    2020-11-16T22:42:10.503+00:00

    I believe that they are logged to the Application Event Log in Windows. I did a quick test, and in that case at least there were entries in the Windows Event Log.

    An indication is also that when you use RAISERROR with level 19 or high, the clause WITH LOG is mandatory, and this clause means that the error will be logged into the Windows event log.

    0 comments No comments

  2. David C 191 Reputation points
    2020-11-17T03:30:51.83+00:00

    Thank you! BTW, I know I can use the EVENTCREATE command to manually force a dummy event into the application event log. May I ask how you tested to put a severity 19+ event in the event log? RAISEERROR sounds good for doing it programatically, but I would like to demonstrate in my own environment how Database Engine can natively put a 19+ in the app log in addition to the SQL Server error log.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.