How to use Log4net from Nuget with Visual Studio in the ASP.NET Web Form (Easy method)(如何在 ASP.NET Web 窗体中使用来自 Nuget 的 Log4net 和 Visual Studio(简单方法))
问题描述
大家好,我知道如何在我的 ASP.NET MVC 项目中快速简便地构建 Log4Net [
第 2 步:
在 Global 请把这句话log4net.Config.XmlConfigurator.Configure();
"放在Application_Start
第 3 步:在Web.Config中请在web.config中写下如下代码
<configSections><节名="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/></configSections><log4net debug="true"><appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"><文件值="logslog.txt"/><appendToFile value="true"/><rollingStyle value="大小"/><maxSizeRollBackups value="10"/><maximumFileSize value="100KB"/><staticLogFileName value="true"/><布局类型="log4net.Layout.PatternLayout"><conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n"/></布局></appender><根><level value="DEBUG"/><appender-ref ref="RollingLogFileAppender"/></root></log4net>
最后一步:
将以下代码放在要记录日志的页面中
private static log4net.ILog Log { get;放;}= log4net.LogManager.GetLogger(typeof(_03_account));protected void Page_Load(object sender, EventArgs e){Log.Debug("调试信息");//log.Warn("警告信息");//log.Error("错误信息");//log.Fatal("致命消息");}
Hi all I know how to quick and easy way to build the Log4Net in my ASP.NET MVC project [Reference],however how to do it in pure " Web Form " project, please help me to solve this issue, step by step thanks.
By the way I have been looking for the some solutions to deal with my problem too,but it isn't good way to me, like as follow question at the Stackoverflow
1. Using log4net with asp.net web forms
2. unable to write logs to a file using log4net in an ASP.NET Web Forms Site
PS: I will been trying solve this issue too, hopefully you or me can find out some good ideas to handle this.
4 steps to handle this issue for web form
Step 1:
Using Nuget to get the Log4Net
Step 2:
In Global please put this sentence "log4net.Config.XmlConfigurator.Configure();
" in the Application_Start
Step 3: In the Web.Config please write down as following code in the web.config
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net debug="true">
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logslog.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="100KB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
Final step:
Putting as following code in one page where you want to record the log
private static log4net.ILog Log { get; set; }= log4net.LogManager.GetLogger(typeof(_03_account));
protected void Page_Load(object sender, EventArgs e)
{
Log.Debug("Debug message");
//log.Warn("Warn message");
//log.Error("Error message");
//log.Fatal("Fatal message");
}
这篇关于如何在 ASP.NET Web 窗体中使用来自 Nuget 的 Log4net 和 Visual Studio(简单方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 ASP.NET Web 窗体中使用来自 Nuget 的 Log4net 和 Visual Studio(简单方法)


- MoreLinq maxBy vs LINQ max + where 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 输入按键事件处理程序 2022-01-01