Errors fix, removed old library, Added logging
This commit is contained in:
parent
8048c41cd0
commit
d8d8b152bd
6 changed files with 179 additions and 89 deletions
|
|
@ -1,11 +1,54 @@
|
|||
using ImageCatalog;
|
||||
using System.Runtime.InteropServices;
|
||||
using ImageCatalog;
|
||||
using ImageCatalog_2.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ImageCatalog_2
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern bool AllocConsole();
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
static extern IntPtr GetStdHandle(int nStdHandle);
|
||||
|
||||
private const int STD_OUTPUT_HANDLE = -11;
|
||||
private const int STD_ERROR_HANDLE = -12;
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
static extern bool SetStdHandle(int nStdHandle, IntPtr handle);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
static extern IntPtr GetConsoleWindow();
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
static extern bool AttachConsole(int dwProcessId);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
static extern IntPtr CreateFile(
|
||||
string lpFileName,
|
||||
uint dwDesiredAccess,
|
||||
uint dwShareMode,
|
||||
IntPtr lpSecurityAttributes,
|
||||
uint dwCreationDisposition,
|
||||
uint dwFlagsAndAttributes,
|
||||
IntPtr hTemplateFile);
|
||||
|
||||
private const uint GENERIC_WRITE = 0x40000000;
|
||||
private const uint OPEN_EXISTING = 3;
|
||||
|
||||
private static void RedirectConsoleOutput()
|
||||
{
|
||||
var stdOutHandle = CreateFile("CONOUT$", GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);
|
||||
var safeFileHandle = new Microsoft.Win32.SafeHandles.SafeFileHandle(stdOutHandle, true);
|
||||
var fileStream = new FileStream(safeFileHandle, FileAccess.Write);
|
||||
var standardOutput = new StreamWriter(fileStream) { AutoFlush = true };
|
||||
Console.SetOut(standardOutput);
|
||||
Console.SetError(standardOutput);
|
||||
}
|
||||
|
||||
public static IServiceProvider ServiceProvider { get; private set; }
|
||||
[STAThread]
|
||||
static void Main()
|
||||
|
|
@ -14,6 +57,9 @@ namespace ImageCatalog_2
|
|||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
AllocConsole();
|
||||
RedirectConsoleOutput();
|
||||
|
||||
var serviceCollection = new ServiceCollection();
|
||||
ConfigureServices(serviceCollection);
|
||||
|
||||
|
|
@ -36,6 +82,12 @@ namespace ImageCatalog_2
|
|||
|
||||
// Register your forms
|
||||
services.AddTransient<MainForm>();
|
||||
|
||||
services.AddLogging(configure =>
|
||||
{
|
||||
configure.AddConsole();
|
||||
configure.SetMinimumLevel(LogLevel.Debug);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue