简体   繁体   English

如何调试NLog数据库目标

[英]How to debug NLog Database target

I have an NLog config that I wish was writing logs to MS SQL. 我有一个NLog配置,希望将日志写入MS SQL。

  <targets>
    <target name="console" xsi:type="Console" layout="${date:format=HH\:mm\:ss}|${level}|${stacktrace}|${message}"/>
    <target xsi:type="Database"
            connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=&quot;F:\...\Logging.mdf\&quot;;Integrated Security=True;Connect Timeout=30"
            commandType="StoredProcedure"
            commandText="[dbo].[int_Log]"
            name="database">
      <parameter name="@TransactionId" layout="transaction-id"/>
      <parameter name="@SectionId" layout="section-id"/>
      <parameter name="@UserId" layout="user-id"/>
      <parameter name="@CompanyCode" layout="company-code"/>
      <parameter name="@CategoryId" layout="category-id"/>
      <parameter name="@Data" layout="data"/>
    </target>
  </targets>

  <rules>
    <!--<logger name="*" minlevel="Trace" writeTo="logfile" />-->
    <logger name="*" minlevel="Info" writeTo="console" />
    <logger name="*" minlevel="Info" writeTo="database" />
  </rules>
</nlog>

This should by invoking the following stored procedure: 应该通过调用以下存储过程来完成:

CREATE PROCEDURE int_Log
    -- Add the parameters for the stored procedure here
    @TransactionId VARCHAR(50),
    @SectionId VARCHAR(50),
    @UserId VARCHAR(50),
    @CompanyCode VARCHAR(50),
    @CategoryId VARCHAR(50),
    @Data VARCHAR(5000)
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

INSERT INTO [dbo].[Logs]
           ([TransactionId]
           ,[SectionId]
           ,[UserId]
           ,[CompanyCode]
           ,[CategoryID]
           ,[Data]
           ,[Id])
     VALUES
           (@TransactionId,
           @SectionId,
           @UserId,
           @CompanyCode,
           @CategoryId,
           @Data,
           NEWID())
END

However, there aren't any new rows appearing in in the table. 但是,表中没有任何新行出现。 How do I go about debugging this? 我该如何调试呢? The problem with the XML config is that it seems to either work, or not. XML配置的问题在于它似乎有效或无效。

Instructions for debug output are here . 调试输出的说明在这里

To log out to the console, just add internalLogToConsole="true" to the <nlog> element, ie: 要注销到控制台,只需将internalLogToConsole="true"添加到<nlog>元素,即:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      internalLogToConsole="true">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM