我有一个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="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>
此应通过调用以下存储过程:
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
但是,表格中没有出现任何新行。我该如何调试呢? XML配置的问题在于它似乎工作与否。
答案 0 :(得分:3)
调试输出的说明是here。
要注销到控制台,只需将Time.utc(2016, 7, 2, 18, 14, 0).in_time_zone("EST").to_s != Time.utc(2016, 7, 2, 18, 14, 0).to_s
添加到internalLogToConsole="true"
元素,即:
<nlog>