增加驱动异常日志

This commit is contained in:
陈国伟 2021-09-24 10:33:42 +08:00
parent 38a20863a6
commit f2b248f18d
2 changed files with 15 additions and 0 deletions

View File

@ -5,6 +5,7 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Buffers.Binary;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net;
@ -62,6 +63,7 @@ namespace FastGithub.PacketIntercept.Dns
var handle = WinDivert.WinDivertOpen(DNS_FILTER, WinDivertLayer.Network, 0, WinDivertOpenFlags.None);
if (handle == IntPtr.MaxValue || handle == IntPtr.Zero)
{
this.logger.LogError($"打开驱动失败");
return;
}
@ -93,6 +95,11 @@ namespace FastGithub.PacketIntercept.Dns
WinDivert.WinDivertSend(handle, winDivertBuffer, packetLength, ref winDivertAddress);
}
}
else
{
var exception = new Win32Exception(Marshal.GetLastWin32Error());
this.logger.LogError(exception.Message);
}
}
}

View File

@ -1,7 +1,9 @@
using Microsoft.Extensions.Logging;
using System;
using System.Buffers.Binary;
using System.ComponentModel;
using System.Net;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
@ -50,6 +52,7 @@ namespace FastGithub.PacketIntercept.Tcp
var handle = WinDivert.WinDivertOpen(this.filter, WinDivertLayer.Network, 0, WinDivertOpenFlags.None);
if (handle == IntPtr.MaxValue || handle == IntPtr.Zero)
{
this.logger.LogError($"打开驱动失败");
return;
}
@ -77,6 +80,11 @@ namespace FastGithub.PacketIntercept.Tcp
WinDivert.WinDivertSend(handle, winDivertBuffer, packetLength, ref winDivertAddress);
}
}
else
{
var exception = new Win32Exception(Marshal.GetLastWin32Error());
this.logger.LogError(exception.Message);
}
}
}