diff --git a/src/Serilog.Sinks.Seq/Sinks/Seq/HttpLogShipper.cs b/src/Serilog.Sinks.Seq/Sinks/Seq/HttpLogShipper.cs index b0e5a52..aa9b7d9 100644 --- a/src/Serilog.Sinks.Seq/Sinks/Seq/HttpLogShipper.cs +++ b/src/Serilog.Sinks.Seq/Sinks/Seq/HttpLogShipper.cs @@ -19,7 +19,6 @@ using System.Linq; using System.Net; using System.Net.Http; -using System.Runtime.InteropServices; using System.Text; using System.Threading; using Serilog.Core; @@ -29,6 +28,10 @@ using System.Threading.Tasks; using System.Collections.Generic; +#if HRESULTS +using System.Runtime.InteropServices; +#endif + namespace Serilog.Sinks.Seq { class HttpLogShipper : IDisposable @@ -394,6 +397,7 @@ static bool IsUnlockedAtLength(string file, long maxLen) return fileStream.Length <= maxLen; } } +#if HRESULTS catch (IOException ex) { var errorCode = Marshal.GetHRForException(ex) & ((1 << 16) - 1); @@ -402,6 +406,12 @@ static bool IsUnlockedAtLength(string file, long maxLen) SelfLog.WriteLine("Unexpected I/O exception while testing locked status of {0}: {1}", file, ex); } } +#else + catch (IOException) + { + // Where no HRESULT is available, assume IOExceptions indicate a locked file + } +#endif catch (Exception ex) { SelfLog.WriteLine("Unexpected exception while testing locked status of {0}: {1}", file, ex); diff --git a/src/Serilog.Sinks.Seq/project.json b/src/Serilog.Sinks.Seq/project.json index b817b7c..3432ceb 100644 --- a/src/Serilog.Sinks.Seq/project.json +++ b/src/Serilog.Sinks.Seq/project.json @@ -19,7 +19,7 @@ "frameworks": { "net4.5": { "buildOptions": { - "define": [ "DURABLE", "WAITABLE_TIMER" ] + "define": [ "DURABLE", "WAITABLE_TIMER", "HRESULTS" ] }, "frameworkAssemblies": { "System.Net.Http": ""