在“日志记录应用程序块"中的日志文件名中添加日期 [英] Add date to log file name in Logging Application Block

查看:323
本文介绍了在“日志记录应用程序块"中的日志文件名中添加日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Microsoft Logging Application Block(版本5 beta 2),并且试图将日志文件的文件名动态设置为年份月份和日期(然后每天写入一个新的日志文件) .但是,在运行时,记录器将忽略任何动态环境变量,例如%date%,%time%或%cd%.我可以将静态环境变量添加到文件名(例如%username%),但不能将动态环境变量添加到文件名.有谁知道如何获取滚动平面文件跟踪侦听器以在日志文件名中动态设置日期?

I'm using the Microsoft Logging Application Block (version 5 beta 2) and I'm trying to dynamically set the file name of a log file to the year month and day (and then write a new log file every day). However, at runtime, the logger ignores any dynamic environment variables such as %date%, %time%, or %cd%. I can add static environment variables to the file name (such as %username%), but not dynamic environment variables. Does anyone know how to get the rolling flat file trace listener to dynamically set the date in the log file name?

(这就是我将文件名设置为:Log_%date%.log)

(this is what I was setting the File Name as: Log_%date%.log)

推荐答案

我放弃了Logging Application Block,转而使用log4net. Log4net允许我使用web.config设置将日志的名称设置为今天的日期.我在代码项目上写了一篇文章,展示了如何使log4net与策略注入应用程序块一起工作这里

I gave up on the Logging Application Block and switched to log4net. Log4net lets me set the name of the log to today's date with a web.config setting. I wrote an article on Code Project that shows how to get log4net working with the Policy Injection Application Block here

这篇关于在“日志记录应用程序块"中的日志文件名中添加日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆