使用存储过程NLOG对目标数据库 [英] Using Stored Procedure in NLog on a Database target

查看:167
本文介绍了使用存储过程NLOG对目标数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#Web应用程序使用时NLOG使用存储过程,而不是一个SQL INSERT语句中有一点小问题。连接字符串记录仪在Web.config中配置正确,并用SQL语句替换的CommandText时正常工作。我希望在正确的方向提示。在这个例子中,存储的过程是在日志模式下,它被称为LOGERROR。

 <靶标GT; 
<目标的xsi:type =数据库
NAME =dberrorlog
的connectionStringName =记录仪
keepConnection =真正的
的CommandText =[日志] [LOGERROR]>
<参数名称=@ PROGNAME布局=MyAppName/>
<参数名称=@ COMPNAME布局=$ {}计算机名/>
<参数名称=@ LogLevel的布局=$ {}级/>
<参数名称=@用户名布局=$ {}身份/>
<参数名称=@错误布局=$ {异常:格式=消息}/>
<参数名称=@ SourceObj布局=$ {异常:格式=方法}/>
<参数名称=@堆栈跟踪布局=$ {异常:格式=堆栈跟踪}/>
< /目标与GT;
< /目标>
<规则与GT;
<记录器名称=*定义的MinLevel =错误的writeTo =dberrorlog/>
< /规则>


解决方案

从这个NLOG的forum帖子,请尝试使用文本来执行存储过程:

 的CommandText =EXEC AddActivityLog 
@ApplicationName,
@ApplicationTime,
@Severity,
@Logger,
@SaxoID,
@事件ID,
@message,
@URL,
@URLReferrer,
@RemoteAddress,
@Callsite,
@CurrentUICulture,
@ThreadIdentity ,
@WindowsIdentity,
@MachineName,
@ProcessID,
@ThreadID,
@ThreadName,
@Stacktrace,
抛出,
@Cookie,
@FormVariables,
@QueryString,
@HTTPUserAgent

边注:克劳斯Rathje的回答将不会在浏览器中呈现,所以我不得不寻找一个页面的源代码,看看他张贴的配置


I am having a bit of a problem using a stored procedure instead of a SQL INSERT statement when using NLog in a C# web application. The connection string "Logger" is correctly configured in Web.config and works properly when replacing the commandText with a SQL statement. I would appreciate a hint in the right direction. In this example the stored procedure is under the "Logs" schema and it is called "LogError".

<targets>
  <target xsi:type="Database"
      name="dberrorlog"
      connectionStringName="Logger"
      keepConnection="true"   
      commandText="[Logs].[LogError]" >
      <parameter name="@ProgName" layout="MyAppName"/>
      <parameter name="@CompName" layout="${machinename}"/>
      <parameter name="@LogLevel" layout="${level}"/>
      <parameter name="@UserName" layout="${identity}"/>
      <parameter name="@Error" layout="${exception:format=Message}"/>
      <parameter name="@SourceObj" layout="${exception:format=Method}"/>
      <parameter name="@StackTrace" layout="${exception:format=StackTrace}"/>
 </target>
</targets>
<rules>
  <logger name="*" minlevel="Error" writeTo="dberrorlog" />
</rules>

解决方案

From this NLog forum post, try using the text to execute the stored procedure:

commandtext="exec AddActivityLog
                            @ApplicationName, 
                            @ApplicationTime, 
                            @Severity, 
                            @Logger, 
                            @SaxoID, 
                            @EventID, 
                            @Message, 
                            @URL, 
                            @URLReferrer, 
                            @RemoteAddress, 
                            @Callsite, 
                            @CurrentUICulture, 
                            @ThreadIdentity, 
                            @WindowsIdentity, 
                            @MachineName, 
                            @ProcessID, 
                            @ThreadID, 
                            @ThreadName, 
                            @Stacktrace, 
                            @Exception,
                            @Cookie,
                            @FormVariables,
                            @QueryString,
                            @HTTPUserAgent"

Side note: Claus Rathje's answer wouldn't render in my browser, so I had to look a the page source to see the configuration he posted.

这篇关于使用存储过程NLOG对目标数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆