事件日志属性相关

发布于 2024-08-13 17:26:02 字数 105 浏览 4 评论 0原文

如何在事件查看器 - 事件日志属性中为日志大小组框(在属性窗口、应用程序事件日志、WIndows XP 操作系统中的事件查看器中)编写 C#.NET 代码。

请向我提供相同的代码。

How to write C#.NET code for Log Size groupbox(in Properties window,Application eventlog,Eventviewer in WIndows XP OS) in EventViewer - Eventlog Properties.

Please provide me the code for the same.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲世九天 2024-08-20 17:26:02

我认为 sukumar 所问的是如何以编程方式更改 C# 中事件日志的大小?

// Get the Event Log
this.eventLog = new EventLog();           
this.eventLog.Source = "Your.Log.Source";

// Configure the Event Log
// Set the log size
this.eventLog.MaximumKilobytes = 5120;
// Ower-write old records when log becomes full
this.eventLog.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, 0);

// Add the trace listner
Trace.Listeners.Add(new EventLogTraceListener(this.eventLog));

如果右键单击事件日志(例如应用程序日志),然后选择属性。您将看到可以设置日志大小。

问题是假设您正在写入一个自定义日志。溢出操作设置为DoNotOverwrite(默认),如果不将其更改为OverwriteAsNeeded,则会当日志变满时抛出异常< /强>。系统日志似乎默认有 OverwriteOlder

增加日志大小只会给你带来更大的历史记录......

I think what sukumar is asking is how can he programatically change the size of an event log in C#?

// Get the Event Log
this.eventLog = new EventLog();           
this.eventLog.Source = "Your.Log.Source";

// Configure the Event Log
// Set the log size
this.eventLog.MaximumKilobytes = 5120;
// Ower-write old records when log becomes full
this.eventLog.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, 0);

// Add the trace listner
Trace.Listeners.Add(new EventLogTraceListener(this.eventLog));

If you righ-click on an event log (eg the Application Log), and select properties. You will see there is a log size that you can set.

The problem is say you have a custom log that you are writing to. The overflow action is set to DoNotOverwrite (by default), if you don't change it to OverwriteAsNeeded, you will throw an exception when the log becomes full. System logs seem to have OverwriteOlder as a default.

Increasing the log size just gives you a bigger history...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文