The line "IF COUNT(*)=2" probably is not doing what you think it is doing. In this context "COUNT(*)" actually returns zero - I suspect that you really want the number of records in the EVENT table.
Also the statement "SELECT COUNT(*) FROM EVENTS" simply returns a number to the application that is Inserting data into table dbo.XXXXX. This is not likely to be what you intended either.
Perhaps the code below is closer to what you want...
CREATE TRIGGER tgr_XXXX
on dbo.XXXXX
AFTER INSERT
AS
BEGIN
-- SELECT COUNT(*) FROM EVENTS
IF (SELECT COUNT(*) FROM EVENTS)=2
RAISERROR ( 50004,16,1)
end