Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 文件大小超出了允许的限制,无法保存在事件日志中_C#_.net_Web Services_Event Viewer - Fatal编程技术网

C# 文件大小超出了允许的限制,无法保存在事件日志中

C# 文件大小超出了允许的限制,无法保存在事件日志中,c#,.net,web-services,event-viewer,C#,.net,Web Services,Event Viewer,获取此异常使用事件日志写入事件查看器时,文件大小超出了允许的限制,无法保存 使用的代码: string cs = "LoggingService"; EventLog elog = new EventLog(); if (!EventLog.SourceExists(cs)) { Even

获取此异常使用
事件日志写入事件查看器时,文件大小超出了允许的限制,无法保存

使用的代码:

                    string cs = "LoggingService";
                    EventLog elog = new EventLog();

                    if (!EventLog.SourceExists(cs))
                    {
                        EventLog.CreateEventSource(cs, cs);
                    }

                    elog.Source = cs;
                    elog.EnableRaisingEvents = true;

                    elog.WriteEntry(message);
堆栈跟踪:

System.ComponentModel.Win32Exception (0x80004005): The file size exceeds the limit allowed and cannot be saved
   at System.Diagnostics.EventLogInternal.get_OldestEntryNumber()
   at System.Diagnostics.EventLogInternal.StartRaisingEvents(String currentMachineName, String currentLogName)
   at System.Diagnostics.EventLogInternal.set_EnableRaisingEvents(Boolean value)
尝试过的事情:

  • 当我将此语句
    elog.Clear()
    放在
    elog.EnableRaisingEvents=true之前时
    我得到了不同的例外

    System.ComponentModel.Win32异常(0x80004005):访问被拒绝 在System.Diagnostics.EventLoginInternal.Clear()中

  • 上述代码由在计算机上具有完全权限的LocalSystem下运行的web服务执行


    操作系统:windows server 2008R2和.NET 4.0有一个方法EventLog.ModifyOverflowPolicy可以修改日志策略。
    我相信EventLog.ModifyOverflowPolicy(OverflowAction.OverwriteasRequired,0)可能会有所帮助。

    事件查看器-属性-最大日志大小为1028。我撞到了它,它开始正常工作

    但在我做出上述更改之前,相同的代码在另一个窗口服务中工作。 这让我想到了可能发生的事情


    我试图记录的消息只是一行(少于255个字符)

    尝试删除事件日志。也许您创建它时使用了不同的帐户,LocalSystem无法访问它。我无法删除自定义事件日志…相同的代码直到昨天才开始工作。我没有修改任何日志,只是创建了一个新日志。我说的是在创建一个新日志后进行修改。这样它就可以得到更合适的策略。@praneth当你创建一个新的日志时,它有一个最大的大小,当达到这个最大值时,你就会得到一个异常,就像你发现的那样。在您创建的新日志上,您需要修改它的策略,以便当它填满时,它开始覆盖最旧的条目。如果您所做的只是增加最大大小,那么当日志填满时,您仍然会再次遇到完全相同的问题(最终会遇到)。如果您正在填充日志并出现异常,而您所做的只是增加日志的最大大小,那么您还没有修复该错误-您只是延迟了它。日志最终将再次填满,然后您将再次遇到完全相同的问题。您需要修改溢出策略,正如aiodintsov的回答中提到的。我可以在一台计算机上复制相同的异常,只需读取事件日志!它也被设置为最大大小1028,但策略是“根据需要覆盖事件”-崩溃枚举(新事件日志(x,y)。条目。。。