.net – System.Diagnostics.EventLog – 连接到系统的设备无法运行
|
我做了一些谷歌,没有任何“设备附加”错误与事件日志有任何关系.我也在Micosoft fourm发布了问题,但没有回复.以为我会给你们一个机会.这里是问题的链接. https://social.msdn.microsoft.com/Forums/en-US/d484d9dc-d9eb-4d19-97b8-9ae4db63e041/systemdiagnosticseventlog-a-device-attached-to-the-system-is-not-functioning?forum=netfxbcl 这是错误消息: System.ComponentModel.Win32Exception was caught
ErrorCode=-2147467259
HResult=-2147467259
Message=A device attached to the system is not functioning
NativeErrorCode=31
Source=System
StackTrace:
at System.Diagnostics.EventLogInternal.InternalWriteEvent(UInt32 eventID,UInt16 category,EventLogEntryType type,String[] strings,Byte[] rawData,String currentMachineName)
at System.Diagnostics.EventLogInternal.WriteEntry(String message,Int32 eventID,Int16 category,Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String message,EventLogEntryType type)
at VB_Braums_ClassLib.LogIt.WriteEventLog(String Entry,EventLogEntryType eventType,String Source) in Corp01Vol1MisPccodeMs.netProductionLibsProductionLibsProdLibCommon.vb:line 3666
InnerException:
这段代码在库中,所以我创建了一个“hello world”来演示这个问题.我会在最后发布.这个.net 4框架已经在我们的代码中存在了一段时间.我们开始从XP升级到Win 7.基本上,事件日志大小限制为32667号码.所以我们进行了测试,如果字符串大于那个,那么我们将把它写成32000字节的卡盘.在两个不同的win7框中,我们收到“设备附加”错误消息.在XP机器上运行相同的代码,它的工作原理.哦,Win 7盒子是64位.我想知道胜利7 32位是否会有同样的问题?其他人可以复制它吗? tmpsize似乎是不同的数字,但如果你玩它,你可以把它降到数字x作品和(x 1)没有.介于30000和32000之间.从大多数snighfict价值开始并向下移动,我打赌它在31000 – 31900范围内. Module Module1
Sub Main()
Dim logName As String = "BraumsLog"
Dim objEventLog As New System.Diagnostics.EventLog()
Dim needCreate As Boolean = False
Dim Source As String = ""
If Source.Length = 0 Then Source = "Test"
Dim Entry As String = "".PadLeft(64000,"1"c)
'Register the App as an Event Source
If EventLog.SourceExists(Source) Then
Dim slog As String = EventLog.LogNameFromSourceName(Source,".")
If slog <> logName Then EventLog.DeleteEventSource(Source) : needCreate = True
Else
needCreate = True
End If
If needCreate Then EventLog.CreateEventSource(Source,logName)
objEventLog.Source = Source
'*************************************
'*********** New Code ****************
objEventLog.MaximumKilobytes = 20480
objEventLog.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded,0)
'*************************************
'*************************************
'WriteEntry is overloaded; this is one
'of 10 ways to call it
Dim tmp As String = ""
Dim tmpSize As Integer = 32000 '31890 works 31891 does not
Do While Entry.Length > tmpSize
tmp = Entry.Substring(0,tmpSize - 1)
objEventLog.WriteEntry(tmp,EventLogEntryType.Information)
Debug.WriteLine(tmp.Length.ToString)
Entry = Entry.Substring(tmpSize)
Loop
tmp = Entry
objEventLog.WriteEntry(tmp,EventLogEntryType.Information)
End Sub
End Module
我们目前也有这个问题.我不确定这是否是解决方案,关于此错误的官方信息是关于软盘而不是日志消息:
https://technet.microsoft.com/en-us/library/cc978749.aspx 但我发现在Log4Net上报告了一个错误,当写入大约30.000个字符的日志消息时,日志文件可能会损坏. 我们现在将重新创建日志文件并在写入新日志条目之前剪切字符串.手指交叉,这有助于(评论赞赏). (编辑:鄂州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
