public bool TryMatchFormat(string fileName, byte[] header, Encoding encoding, out ILogFileFormat format, out Certainty certainty) { try { if (_inner == null) { format = null; certainty = Certainty.Sure; return(false); } return(_inner.TryMatchFormat(fileName, header, encoding, out format, out certainty)); } catch (Exception e) { Log.ErrorFormat("Caught unexpected exception: {0}", e); format = null; certainty = Certainty.Uncertain; return(false); } }
public bool TryMatchFormat(string fileName, byte[] initialContent, out ILogFileFormat format) { try { return(_inner.TryMatchFormat(fileName, initialContent, out format)); } catch (Exception e) { Log.ErrorFormat("Caught unexpected exception: {0}", e); format = null; return(false); } }
private ILogFileFormat TryFindFormat(FileStream stream) { var pos = stream.Position; const int maxHeaderLength = 512; var length = Math.Min(maxHeaderLength, stream.Length - pos); var header = new byte[length]; stream.Read(header, 0, header.Length); ILogFileFormat format = null; _formatMatcher?.TryMatchFormat(_fullFilename, header, out format); if (format == null && length == maxHeaderLength) { return(LogFileFormats.GenericText); } return(format); }
private ILogFileFormat TryFindFormatOf(string fileName, Stream stream, Encoding encoding, out Certainty certainty) { stream.Position = 0; const int maxHeaderLength = 512; var length = Math.Min(maxHeaderLength, stream.Length); var header = new byte[length]; stream.Read(header, offset: 0, header.Length); _formatMatcher.TryMatchFormat(fileName, header, encoding, out var format, out certainty); if (format != null) { return(format); } certainty = header.Length >= maxHeaderLength ? Certainty.Sure : Certainty.Uncertain; return(LogFileFormats.GenericText); }