简体   繁体   English

如何使用企业库使记录器覆盖C#中的旧日志文件?

[英]How can I get my logger to overwrite old log file in C# using Enterprise Library?

Using Enterprise Library 3.1, I have a logger that, once it reaches its "rollSizeKB" refuses to overwrite the log file. 使用Enterprise Library 3.1,我有一个记录器,记录器一旦到达其“ rollSizeKB”,便拒绝覆盖日志文件。 What am I missing? 我想念什么?

<listeners>
  <add formatter="Text Formatter"
       listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
       traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
       rollSizeKB="1"
       rollInterval="None"
       rollFileExistsBehavior="Overwrite"           
       name="Formatted EventLog TraceListener"
       fileName="logfile.log"/>
</listeners>

For my testing purposes, I have the rollSizeKB purposely small. 出于测试目的,我故意将rollSizeKB设置得很小。 Once logfile.log hits 1KB, it stops writing to the file and will not overwrite it. 一旦logfile.log达到1KB,它将停止写入文件并且不会覆盖该文件。 What am I missing? 我想念什么?

I'm not 100% sure what is going on but this sounds like it could be a permission problem. 我不确定100%发生了什么,但这听起来可能是权限问题。

Can you check the permissions on the folder that logfile.log is in? 您可以检查logfile.log所在文件夹的权限吗? As a check: if there are no Deny permissions set, then grant Everyone Full Control on the folder and rerun your program to see if that makes a difference. 作为检查:如果没有设置“拒绝”权限,则在文件夹上授予“所有人完全控制”,然后重新运行程序以查看是否有区别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM