[英]Log4net won't Register in database using AdoNetAppender MVC
I'm new in log4net logger and I'm trying to create logger using AdoNetAppender to save the logs to a database.我是 log4net 记录器的新手,我正在尝试使用 AdoNetAppender 创建记录器以将日志保存到数据库。
When I use the Simple Layout当我使用简单布局时
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
and for saving to the database:并保存到数据库:
<commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />
<parameter>
<parameterName value="@log_date" />
<dbType value="DateTime" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
<parameter>
<parameterName value="@thread" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%thread" />
</layout>
</parameter>
It successfully saves to the database;成功保存到数据库; the issue is that i need to register more details (location, method, line) but it fail to save that in the database.问题是我需要注册更多详细信息(位置、方法、行),但无法将其保存在数据库中。
For that I used the following configuration:为此,我使用了以下配置:
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger %location
%method %line - %message %newline" />
</layout>
And for database inserting:对于数据库插入:
<commandText value="INSERT INTO Log( [Date],[Thread],[Level],[Logger],
[Locaotion],[Method],[Line],[Message],[Exception])
VALUES (@log_date, @thread, @log_level,
@logger,@location @method, @line, @message, @exception)" />
<parameter>
<parameterName value="@location" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%location" />
</layout>
</parameter>
<parameter>
<parameterName value="@method" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%method" />
</layout>
</parameter>
<parameter>
<parameterName value="@line" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%line" />
</layout>
</parameter>
My C# code :我的 C# 代码:
private static ILog log = LogManager.GetLogger(typeof(HomeController));
//private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
How can I save the full error details in the database?如何在数据库中保存完整的错误详细信息?
I get the error i was forget a (,) in database inserting code ans i add Application_Error in global我收到错误,我在数据库插入代码中忘记了一个 (,) 并且我在全局中添加了 Application_Error
conversionPattern Code:转换模式代码:
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%location] [%method] [%line] - %message %newline" />
</layout>
database inserting code :数据库插入代码:
<commandText value="INSERT INTO Log( [Date],[Thread],[Level],[Logger],[Location],[Method],[Line],[Message],[Exception])
VALUES (@log_date, @thread, @log_level, @logger, @location, @method, @line, @message, @exception)" />
and for global code :和全局代码:
private static readonly ILog log = LogManager.GetLogger(typeof(MvcApplication));
private void Application_Error(Object sender, EventArgs e)
{
var ex = Server.GetLastError().GetBaseException();
log.Error("App_Error", ex);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.