
CREATE PROCEDURE DBO.WriteToFileLog @ALogFileName VARCHAR(100), @ALogText VARCHAR(3900), @ALogFilePath VARCHAR(100)= '' AS

/*
  Created by Kent Johansen on 24/8 2006
  writes logtext to a logfile
*/

IF (@ALogFileName <> '') AND (@ALogText <> '')
BEGIN
  DECLARE @sql NVARCHAR(4000)
  
  IF @ALogFilePath <> ''
  BEGIN
    SET @sql = N'exec master.dbo.xp_cmdshell ''mkdir "' + @ALogFilePath + '"'''
    EXEC sp_executesql @sql
  END

  SET @sql = N'exec master..xp_cmdshell ''echo ' + @ALogText + ' >> ' + @ALogFileName + ''''
  EXEC sp_executesql @sql
END

