/*============================================================================
  File:     TVFEventLog.sql

  Summary:  This script reads the event log.

  Date:     April 2005

  Tested on SQL Server Version: 9.00.1116.08 (IDW14 - April CTP)
------------------------------------------------------------------------------
  Copyright (C) 2005 Kimberly L. Tripp, SYSolutions, Inc.
  All rights reserved.

  For more scripts and sample code, check out 
    http://www.SQLskills.com

  This script is intended only as a supplement to demos and lectures
  given by Kimberly L. Tripp.  
  
  THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF 
  ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED 
  TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  PARTICULAR PURPOSE.
============================================================================*/

USE SimpleDeploy
GO

CREATE ASSEMBLY [EventLog]
  AUTHORIZATION dbo
FROM 'C:\SYSolutions, Inc\ConferenceSessions\TechEd\200506 Orlando\DAT250-BridgingGap\EventLog\EventLog\bin\Debug\EventLog.dll'
  WITH permission_set = unsafe
GO

CREATE FUNCTION TVLog 
(
	@logname nvarchar (16)
)
RETURNS TABLE 
( 
	[Time] datetime,
  	[Message] nvarchar(1000),
	Category nvarchar (40),
	InstanceID int
)
AS
EXTERNAL NAME EventLog.TVLog.InitMethod
go

-- Clear the log, stop and restart SQL and then run this...
-- If you add an order by to get the last bit of the application log it 
-- will still need to read the error log...large log may take some time!
SELECT Top 10 * FROM dbo.TVLog(N'Application')

