Microsoft Enterprise Library无法通过ODBC写入日志

时间:2014-09-17 16:36:33

标签: c# sql-server stored-procedures odbc enterprise-library

在我的应用程序中,MEL设置为使用基于GenericDatabase(ODBC)的数据库侦听器,如下所示:

GenericDatabase db = new GenericDatabase(_connectionString, OdbcFactory.Instance);
TraceListener traceListener = new FormattedDatabaseTraceListener(db, _writeLogStoredProcName, _addCategoryStoredProcName, _formatter);

ODBC设置为连接到SQL Server驱动程序。 “WriteLog”存储过程如下所示:

ALTER PROCEDURE [dbo].[WriteLog]
(
    @EventId int, 
    @Priority int, 
    @Severity nvarchar(32), 
    @Title nvarchar(256), 
    @Timestamp datetime,
    @MachineName nvarchar(32), 
    @AppDomainName nvarchar(512),
    @ProcessID nvarchar(256),
    @ProcessName nvarchar(512),
    @ThreadName nvarchar(512),
    @Win32ThreadId nvarchar(128),
    @Message nvarchar(1500),
    @FormattedMessage ntext,
    @LogId int OUTPUT
)
AS 

    INSERT INTO [LOG] (
        EVENTID,
        PRIORITY,
        SEVERITY,
        TITLE,
        [TIMESTAMP],
        MACHINENAME,
        APPDOMAINNAME,
        PROCESSID,
        PROCESSNAME,
        THREADNAME,
        WIN32THREADID,
        MESSAGE,
        FORMATTEDMESSAGE
    )
    VALUES (
        @EventId, 
        @Priority, 
        @Severity, 
        @Title, 
        @Timestamp,
        @MachineName, 
        @AppDomainName,
        @ProcessID,
        @ProcessName,
        @ThreadName,
        @Win32ThreadId,
        @Message,
        @FormattedMessage)

    SET @LogID = @@IDENTITY
    RETURN @LogID

当我执行以下代码时,出现错误:

LogEntry logEntry = new LogEntry();
logEntry.Message = "Test Message";
logEntry.Priority = 1;
logEntry.Categories.Add("Error");

LogWriter logWriter = GetLogger();

// ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Procedure or function 'WriteLog' expects parameter '@EventID', which was not supplied.
logWriter.Write(logEntry);

由于某些原因,参数未传递到我的存储过程中,我通过SQL Server分析器验证了它。当SP执行时,探查器仅显示:

WriteLog

我还尝试将SP参数的标题更改为具有各种命名,例如:@eventid,@ EVENTID,@ eventID,@ EventID,但没有任何效果。

可能是什么问题?

1 个答案:

答案 0 :(得分:0)

我还没有找到有关我的问题的任何信息,所以我最终创建了自己的自定义日志库,包含Blackjack和妓女。