Skip to content

Commit

Permalink
Merge pull request #36 from nblumhardt/dev
Browse files Browse the repository at this point in the history
Fixes #33 - HRESULTs are only generally available on .NET Framework
  • Loading branch information
nblumhardt authored Oct 4, 2016
2 parents 8ce5614 + 6ac7d54 commit ffe1d38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/Serilog.Sinks.Seq/Sinks/Seq/HttpLogShipper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Serilog.Sinks.Seq/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"frameworks": {
"net4.5": {
"buildOptions": {
"define": [ "DURABLE", "WAITABLE_TIMER" ]
"define": [ "DURABLE", "WAITABLE_TIMER", "HRESULTS" ]
},
"frameworkAssemblies": {
"System.Net.Http": ""
Expand Down

0 comments on commit ffe1d38

Please sign in to comment.