mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-20 04:48:53 +00:00
Fixed the '\0' in the log from breaking the XmlReader.
This commit is contained in:
parent
d0a0797e83
commit
ac72e642e8
3 changed files with 50 additions and 3 deletions
|
|
@ -52,6 +52,7 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ErrorStrippingFileStream.cs" />
|
||||
<Compile Include="Handlers\LogHandler.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
|
|
|
|||
38
source/Cosmos.Kernel.LogTail/ErrorStrippingFileStream.cs
Normal file
38
source/Cosmos.Kernel.LogTail/ErrorStrippingFileStream.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace Cosmos.Kernel.LogTail
|
||||
{
|
||||
public class ErrorStrippingFileStream : FileStream
|
||||
{
|
||||
public ErrorStrippingFileStream(string file)
|
||||
: base(file, FileMode.Open, FileAccess.ReadWrite, FileShare.Delete | FileShare.ReadWrite)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override int ReadByte()
|
||||
{
|
||||
int result;
|
||||
while ((result = base.ReadByte()) == 0) ;
|
||||
return result;
|
||||
}
|
||||
|
||||
public override int Read(byte[] array, int offset, int count)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
int b = ReadByte();
|
||||
if (b == -1)
|
||||
return i;
|
||||
|
||||
array[offset + i] = (byte) b;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -45,8 +45,8 @@ namespace Cosmos.Kernel.LogTail
|
|||
|
||||
private void CreateReader()
|
||||
{
|
||||
|
||||
_fs = new FileStream(_file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
|
||||
_fs = new ErrorStrippingFileStream(_file);
|
||||
|
||||
_watching = true;
|
||||
_watcher_Changed(this, new FileSystemEventArgs(WatcherChangeTypes.All, "", ""));
|
||||
|
|
@ -78,8 +78,16 @@ namespace Cosmos.Kernel.LogTail
|
|||
if (_watching)
|
||||
{
|
||||
XmlReader _reader = CreateXmlReader();
|
||||
while (_reader.Read())
|
||||
bool reading = true;
|
||||
while (reading)
|
||||
{
|
||||
try
|
||||
{
|
||||
reading = true;
|
||||
reading = _reader.Read();
|
||||
}
|
||||
catch { }
|
||||
|
||||
LogMessage message = new LogMessage(_reader.Name);
|
||||
for (int i = 0; i < _reader.AttributeCount; i++)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue