如何配置Entlib5.0使得可以按日期存放日志?

pig357 2015-05-22 06:55:19
环境:VS2008 C# 微软企业库Entlib5.0
问题:项目经理要求改用Entlib实现日志记录功能。现在查找资料后,还有以下问题没有解决;
(1)日志保存不是按每天保存的,
(2)记录的内容里面,时间和当前时间对不上。
配置文件:

<?xml version="1.0" encoding="utf-8"?>
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="Info">
<listeners>
<add name="Rolling Flat File Trace Listener"
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="log/日志.txt"
formatter="Text Formatter"
rollFileExistsBehavior="Increment"
footer=""
header=""
timeStampPattern="yyyy-MM-dd"
rollInterval="Day"
rollSizeKB="1000" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="{timestamp} [{category}] - {message} "
name="Text Formatter" />
</formatters>
<logFilters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
enabled="true" name="Logging Enabled Filter" />
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.PriorityFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Priority Filter" />
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.CategoryFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Category Filter" />
</logFilters>
<categorySources>
<add switchValue="All" name="Info">
<listeners>
<add name="Rolling Flat File Trace Listener" />
</listeners>
</add>
<add switchValue="All" name="Trace">
<listeners>
<add name="Rolling Flat File Trace Listener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
</listeners>
</errors>
</specialSources>
</loggingConfiguration>

写日志代码

LogWriter logWriter = null;
logWriter = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();
LogEntry ent = new LogEntry();
ent.Categories.Add("Info");//种类最好根据配置文件定义个枚举
while(true)
{
logWriter.Write("文件操作完成!" + name.ToString() + " " + DateTime.Now.ToString());
Thread.Sleep(100);
}


记录的日志内容:

发现小时是错误的。

请问这两个问题该怎么修改?
...全文
149 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
pig357 2015-05-26
  • 打赏
  • 举报
回复
引用 11 楼 starfd 的回复:
整个配置里面所有这样的都删了?
刚才没有完全删除,所以报错,现在全部删除后可以正常运行了。 非常感谢你的帮助!
  • 打赏
  • 举报
回复
整个配置里面所有这样的都删了?
pig357 2015-05-26
  • 打赏
  • 举报
回复
引用 9 楼 starfd 的回复:
Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
就是指上面这种文本去掉
这个我试过了,还是不行,报的错和上面一样。
  • 打赏
  • 举报
回复
Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
就是指上面这种文本去掉
pig357 2015-05-26
  • 打赏
  • 举报
回复
引用 7 楼 starfd 的回复:
要把那些指定token的去掉才行,否则你得把整个所有的dll都编译发布下
请问这个“指定token的去掉”是什么意思,怎么弄的?
  • 打赏
  • 举报
回复
要把那些指定token的去掉才行,否则你得把整个所有的dll都编译发布下
pig357 2015-05-25
  • 打赏
  • 举报
回复
引用 5 楼 starfd 的回复:
我那个是6.0的,你要下5.0的改,去微软官方下载个,然后改下就可以了


我这边修改后重新编译了Microsoft.Practices.EnterpriseLibrary.Logging.dll,在引用到项目中时编译无错,运行时报错。

在你给的那个链接上也提到了这个问题,但是没有解决方法。请问这个问题该怎么办?
  • 打赏
  • 举报
回复
我那个是6.0的,你要下5.0的改,去微软官方下载个,然后改下就可以了
pig357 2015-05-25
  • 打赏
  • 举报
回复
引用 2 楼 starfd 的回复:
http://blog.csdn.net/starfd/article/details/42913667 按实际时间记录要改源代码
请问有没有改好的库,我这边是vs2008,打不开源程序啊
super_admi 2015-05-22
  • 打赏
  • 举报
回复
……一定要Entlib?我在JAVA上用log4j,在C#上用log4net,感觉挺好的啊。
  • 打赏
  • 举报
回复
http://blog.csdn.net/starfd/article/details/42913667 按实际时间记录要改源代码
  • 打赏
  • 举报
回复
日志格式里面设置(local),这个查看下帮助就知道了
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"  
        template="Timestamp: {timestamp(local)}{newline}  
Message: {message}{newline}  
Category: {category}{newline}  
Priority: {priority}{newline}  
EventId: {eventid}{newline}  
Severity: {severity}{newline}  
Title:{title}{newline}  
Extended Properties: {dictionary({key} - {value}{newline})}"  
        name="Text Formatter" />

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧