简体   繁体   中英

How to debug NLog Database target

I have an NLog config that I wish was writing logs to 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.

Instructions for debug output are here .

To log out to the console, just add internalLogToConsole="true" to the <nlog> element, ie:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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