Code that return the recent warning type record in application log

Code that return the recent warning type record in application log.

 

declare @result varchar(1000)

create table #log_logicalname (result varchar(100))

INSERT INTO #log_logicalname (result)exec xp_cmdshell 'eventquery /r 5 /l application'

select  @result = result  from #log_logicalname where result like '%source%'

set @result = @result + ' '

select  @result = @result + result  from #log_logicalname where result like '%warning%'

print @result

drop table #log_logicalname

 

Code to add trigger if any error record added in application log

eventtriggers /create /tr "triggerName" /l apllication /t error /tk c:\windows\system32\calc.exe

 

Code to delete trigger

eventtriggers /delete /tid 1