长话短说,我使用的是Log4net,我想在内部写入调用存储过程的数据库。以下是web.config中的设置:
<log4net debug="true">
<root>
<level value="ALL" />
<appender-ref ref="AdoNetAppender" />
<appender-ref ref="RollingLogFileAppender" />
</root>
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<threshold value="ALL"/>
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="data source=***;initial catalog=***;user id=**;password=***;MultipleActiveResultSets=True;" />
<commandText value="iE_AddUserActivityLog" />
<commandType value="StoredProcedure" />
<parameter>
<parameterName value="@log_date" />
<dbType value="DateTime" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
<parameter>
<parameterName value="@thread" />
<dbType value="AnsiString" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%thread" />
</layout>
</parameter>
<parameter>
<parameterName value="@log_level" />
<dbType value="AnsiString" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level" />
</layout>
</parameter>
<parameter>
<parameterName value="@logger" />
<dbType value="AnsiString" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%logger" />
</layout>
</parameter>
<parameter>
<parameterName value="@page" />
<dbType value="AnsiString" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{page}" />
</layout>
</parameter>
<parameter>
<parameterName value="@host" />
<dbType value="AnsiString" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{host}" />
</layout>
</parameter>
<parameter>
<parameterName value="@ipaddress" />
<dbType value="AnsiString" />
<size value="15" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{ipaddress}" />
</layout>
</parameter>
<parameter>
<parameterName value="@browser" />
<dbType value="AnsiString" />
<size value="15" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{browser}" />
</layout>
</parameter>
<parameter>
<parameterName value="@platform" />
<dbType value="AnsiString" />
<size value="15" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{platform}" />
</layout>
</parameter>
<parameter>
<parameterName value="@device" />
<dbType value="AnsiString" />
<size value="15" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{device}" />
</layout>
</parameter>
<parameter>
<parameterName value="@message" />
<dbType value="AnsiString" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
</layout>
</parameter>
<parameter>
<parameterName value="@exception" />
<dbType value="AnsiString" />
<size value="2000" />
<layout type="log4net.Layout.ExceptionLayout" />
</parameter>
</appender>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logs\log.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
</layout>
</appender>
</log4net>
有人可以帮我解释为什么我不能使用commandType吗?因为如果我使用:
<commandText value="INSERT INTO user_activity_log ([Date],[Thread],[Level],[Logger],[page],[host],[browser],[platform],[device],[ipaddress],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @page, @host, @browser, @platform, @device, @ipaddress, @message, @exception)" />
或:
<commandText value="exec iE_AddUserActivityLog @log_date, @thread, @log_level, @logger, @page, @host, @browser, @platform, @device, @ipaddress, @message, @exception" />
我可以看到这是写作。
更新:我还试图以这种方式介绍DBO前缀:
<commandText value="dbo.iE_AddUserActivityLog" />
<commandType value="StoredProcedure" />
答案 0 :(得分:0)
好的,我能够解决它。但我不确定为什么。基本上,我需要重命名web.config中的一些参数,以便与我在存储过程中使用的名称相匹配。