惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hacker News: Ask HN
Hacker News: Ask HN
Last Week in AI
Last Week in AI
J
Java Code Geeks
V
Visual Studio Blog
The Cloudflare Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
宝玉的分享
宝玉的分享
博客园 - Franky
博客园 - 【当耐特】
Jina AI
Jina AI
月光博客
月光博客
T
Tailwind CSS Blog
Recent Announcements
Recent Announcements
Apple Machine Learning Research
Apple Machine Learning Research
SecWiki News
SecWiki News
H
Heimdal Security Blog
Y
Y Combinator Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hacker News - Newest:
Hacker News - Newest: "LLM"
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
MongoDB | Blog
MongoDB | Blog
Forbes - Security
Forbes - Security
S
SegmentFault 最新的问题
The GitHub Blog
The GitHub Blog
L
LINUX DO - 最新话题
M
MIT News - Artificial intelligence
Schneier on Security
Schneier on Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
O
OpenAI News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
Schneier on Security
罗磊的独立博客
Microsoft Azure Blog
Microsoft Azure Blog
爱范儿
爱范儿
C
Check Point Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
AI
AI
大猫的无限游戏
大猫的无限游戏
MyScale Blog
MyScale Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Troy Hunt's Blog
T
The Blog of Author Tim Ferriss

博客园 - flyfish

Microsoft SQL Server 2005 -- 错误 29503。SQL Server 服务无法启动 模拟鼠标移动和左键单击 .C# 获取另一程序控件,改变值,触发事件 - flyfish - 博客园 在ASP程序中调用Web Service ASPNET2.0中读写Cookie的方法! - flyfish - 博客园 转 跨域读取Cookie和session之HttpWebRequest另类方法(网站API开发) ASP.NET WAP开发 用ASP.NET创建移动Web窗体[转] ASP.NET 2.0移动开发入门之使用模拟器 [WAP]dotNet在WAP应用开发中实现按指定页数翻页的解决方案 SQL Server 自增字段归零等问题 ntext replace sql SQLServer2005数据库还原到SQLServer2000 如何去除Google搜索结果病毒提示 Tomcat 6 连接 MS SQL 2005 Windows 2003远程桌面连接数限制 如何用SQL命令修改字段名称 FCKeditor详细的设置 两个sql server 2000的通用分页存储过程
log4net 配置与应用
flyfish · 2008-11-16 · via 博客园 - flyfish

在ASP.NET web 站点中使用log4net(独立的配置文件)的步骤和注意事项:
1 添加log4net.dll的引用
2.创建Config/log4net.config(名字可自定义)文件,其内容请参考 log4net 网站 log4net Manual - Configuration 部分
下面一个文本记录的例子.

Code


3.修改global.asax.cs 文件添加以下代码

     //添加的第一行 
    [assembly: log4net.Config.XmlConfigurator(ConfigFile = "Config/Log4net.config", Watch = true)]

    void Application_Start(object sender, EventArgs e) 
    {
        // 在应用程序启动时运行的代码
        HttpContext current = HttpContext.Current;
        string fileName = current.Request.PhysicalApplicationPath + "Config/Log4net.config";
        log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(fileName)); 
    } 

4. 开始写 logger 语句,详情还请参考 log4net 网站
要输出日志, 必须首先得到带有一个别名的logger.
使用以下命令
(C#):
log4net.ILog Logger logger = log4net.LogManager.GetLogger(this.GetType());
(可以直接使用GetType得到当前类名)
之后调用
logger.Info(string message);
logger.Error(string message);
logger.Debug(string message);
即可输出日志.
调试后可查找应用程序根目录下是否已经自动创建log.txt文本文件.以及是否正确输出了日志

注意事项:
需要对日志文件所在的目录设置适当的安全性,以使 ASP.NET 运行帐户可以创建和修改log文件,
此文件在Global的 Application_Start事件后会立即创建(如果不存在的话)。