當在SQL Server 2005數據庫中插入行時,我在Environment,ApplicationName,ApplicationPath,ExceptionData中獲取空值。log4net將錯誤保存到數據庫,獲取參數中的空值
我log4net的配置如下:
<log4net>
<appender name="ADONetAppender_SqlServer" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="Data Source=xxx;Initial Catalog=xxx;User Id=xxx;Password=xx;Connection Timeout=200;" />
<commandText value="INSERT INTO [ApplicationLog] ([TimeStamp],[SeverityLevel],[LoggerName],[Environment],[ApplicationName],[ApplicationPath],[ServerName],[Message],[ExceptionData]) VALUES (@TimeStamp,@SeverityLevel,@LoggerName,@Environment,@ApplicationName,@ApplicationPath,@ServerName,@Message,@ExceptionData)" />
<parameter>
<parameterName value="@TimeStamp" />
<dbType value="DateTime" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
<parameter>
<parameterName value="@SeverityLevel" />
<dbType value="String" />
<size value="10" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level" />
</layout>
</parameter>
<parameter>
<parameterName value="@LoggerName" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%logger" />
</layout>
</parameter>
<parameter>
<parameterName value="@Environment" />
<dbType value="String" />
<size value="-1" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{EnvironmentName}" />
</layout>
</parameter>
<parameter>
<parameterName value="@ApplicationName" />
<dbType value="String" />
<size value="128" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{AppName}" />
</layout>
</parameter>
<parameter>
<parameterName value="@ApplicationPath" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{AppPath}" />
</layout>
</parameter>
<parameter>
<parameterName value="@ServerName" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{log4net:HostName}" />
</layout>
</parameter>
<parameter>
<parameterName value="@Message" />
<dbType value="String" />
<size value="-1" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
</layout>
</parameter>
<parameter>
<parameterName value="@ExceptionData" />
<dbType value="String" />
<size value="-1" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{exceptionDetails}" />
</layout>
</parameter>
</appender>
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
<to value="xxx" />
<from value="xxx" />
<subject value="(Error) xxx" />
<smtpHost value="xxx" />
<bufferSize value="1" />
<lossy value="false" />
<threshold value="ERROR" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%utcdate [%thread] %-5level %logger [%property{log4net:HostName}] - %message%newline%newlineException details:%newline%property{exceptionDetails}" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="ADONetAppender_SqlServer" />
<appender-ref ref="SmtpAppender" />
</root>
在Global.asax,的Application_Error,我叫log4net的配置,然後再登錄異常如下:
Dim ex As New Exception
ex = Server.GetLastError
log4net.Config.XmlConfigurator.Configure()
log.Logger.Log(ex.Source.GetType, log4net.Core.Level.Fatal, ex.StackTrace, ex)
我在做什麼錯?