Reputation: 28510
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="F:\...\Logging.mdf\";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.
Upvotes: 3
Views: 2002
Reputation: 28510
Instructions for debug output are here.
To log out to the console, just add internalLogToConsole="true"
to the <nlog>
element, i.e.:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
internalLogToConsole="true">
Upvotes: 5