事件日志文件已满

发布于 08-02 11:33 字数 434 浏览 6 评论 0原文

尝试从控制台应用程序写入事件日志时,我不断收到此错误消息。 这是我写的方式

public static void WriteToEventLog(Exception ex)
    {
        string mySource = "Export Task";
        if (!EventLog.SourceExists(mySource))
            EventLog.CreateEventSource(mySource, "Application");

        EventLog myLog = new EventLog();
        myLog.Source = mySource;

        myLog.WriteEntry(ex.ToString());

    }

有谁知道为什么会发生这种情况以及我该如何解决它?

I keep getting this error message when trying to write to the Event log from a console app.
Here's how i write to it

public static void WriteToEventLog(Exception ex)
    {
        string mySource = "Export Task";
        if (!EventLog.SourceExists(mySource))
            EventLog.CreateEventSource(mySource, "Application");

        EventLog myLog = new EventLog();
        myLog.Source = mySource;

        myLog.WriteEntry(ex.ToString());

    }

Does anyone know why this is happening and how i can fix it?

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

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

发布评论

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

评论(7

你的心境我的脸2024-08-09 11:33:30

对我来说,这听起来像是:

  • 发生这种情况是因为事件日志已满。
  • 通过清空事件日志来修复它。

如果情况并非如此,请编辑您的问题,以明确您认为事件日志未满,以及您如何得出此结论。

To me it sounds like:

  • It's happening because the event log is full.
  • Fix it by emptying the event log.

If this isn't the case, please edit your question to make it clear that you believe the event log isn't full, and how you came to this conclusion.

ヤ经典坏疍2024-08-09 11:33:30

我在使用 Visual C# 2010 Express 的 Windows XP 上遇到了同样的错误,这对我有用:

转到“开始”->“控制面板”->“管理工具”->“事件查看器”,

然后选择“操作”->“属性”并选择“覆盖”根据需要进行事件”

您还可以增加日志的最大大小。

I had the same error on Windows XP using Visual C# 2010 Express and this is what worked for me:

Go to Start->Control Panel->Administrative Tools->Event Viewer

Then select Action->Properties and select "Overwrite Events as Needed"

You could also increase the maximum size of the log.

酒废2024-08-09 11:33:30

如果打开事件查看器,右键单击相关事件日志并选择“属性”,您可以看到事件日志大小。您可以将其放大或将其下面的选项更改为“根据需要覆盖事件”。

If you open the event viewer, right click on the event log in question and select "properties" you can see the event log size. You can make it larger or change the options below it to say "Overwrite events as needed".

森末i2024-08-09 11:33:30

最有可能的情况是,您正在使用默认的应用程序日志,该日志通常由您计算机上的几乎所有应用程序写入(就像您编写的应用程序一样)。随着时间的推移,事件日志会填满并达到最大值,

因此我的建议是创建一个 新的自定义事件日志而不是重用“应用程序”日志。这样您就可以捕获此异常(这是一个有效的情况)并通过调用 EventLog.Clear &重试写入事件操作。还要检查您是否淹没了事件日志,负责任地记录。

另一方面,您还可以更改应用程序日志的事件日志属性。 (事件查看器,调出应用程序日志节点上的属性) - 您可以指定日志的最大大小 (512 KB) 以及如何处理包装,例如,在达到最大大小时覆盖超过 7 天的条目。 (这似乎是我的 WinXP 机器上的默认设置)。但你必须在每台机器上都这样做......但你可以尝试一下

Most likely scenario, you're using the default Application log which is usually written to by almost any app on your machine (just like the one you wrote). Over time the event log fills up and reaches its maximum

So my suggestion would be to create a new custom event log instead of reusing the "Application" log. That way you can catch this exception (which is a valid case) and handle it by calling EventLog.Clear & retrying the write event operation. Also check if you're flooding the event log, log responsibly.

On the other hand, you could also change the event log properties for the Application log. (Event Viewer, Bring up properties on the Application log node) - You can specify the max size of the log (512 KB) as well as how to handle wrapping e.g. Overwrite entries older than 7 days when the max size is reached. (This seems to be the default on my WinXP machine). But you'd have to do this on every machine... but its something that you could try

总以为2024-08-09 11:33:30

自定义事件日志源的默认大小为 512k。这已经咬了我好几次了。您可以覆盖它以使其大小更加合理(特别是如果您正在出于调试目的编写信息日志)。

Custom event log sources have a default size of 512k. This has bit me several times. You can override this to make it a much more sane size (especially if you are writing a log of information for debug purposes).

与风相奔跑2024-08-09 11:33:30

您尝试过以下代码吗?

log.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, log.MinimumRetentionDays);

Have you tried following code?

log.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, log.MinimumRetentionDays);
迟到的我2024-08-09 11:33:30

启动事件查看器
选择您的事件日志并右键单击,点击“属性”
增加最大日志大小(以 KB 为单位)(这必须是 64 KB 的倍数,但如果您输入一个数字,如果不是倍数,则会进行更正。例如,生产中的声音值可能是 100 MB ,因此可以在此处输入 100,000。

如果日志仍然已满,您可能不希望覆盖事件,这表示错误的日志记录或频繁记录并发生的错误。

请注意,在生产中, https://i.sstatic.net/cymPu.png" rel="nofollow noreferrer">事件日志属性

Start Event viewer
Choose your event log and right click, hit 'Properties'
Bump up the maximum log size in KB (this must be in multiples of 64 KB, but if you enter a number it will be corrected if this is not the case to be a multiple. A sound value in production could be 100 MB for example, so 100,000 for example could be inputted here.

Note, in production you probably do not want to overwrite events if the log still gets full. This is indicative of erroneous logging or an error which is frequently logged and occurs.

Event log properties

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