mirror of
https://github.com/yaakov-h/Notepad.Extensions.Logging.git
synced 2024-11-22 11:14:50 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
df8de16c8d
2 changed files with 49 additions and 3 deletions
|
@ -84,8 +84,28 @@ namespace Microsoft.Extensions.Logging
|
|||
|
||||
static void WriteToNotepad(string message)
|
||||
{
|
||||
IntPtr hwnd = WindowFinder.FindNotepadWindow();
|
||||
NativeMethods.SendMessage(hwnd, NativeMethods.EM_REPLACESEL, (IntPtr)1, message);
|
||||
IntPtr hwnd = FindNotepadWindow();
|
||||
IntPtr edit = NativeMethods.FindWindowEx(hwnd, IntPtr.Zero, "EDIT", null);
|
||||
NativeMethods.SendMessage(edit, NativeMethods.EM_REPLACESEL, (IntPtr)1, message);
|
||||
}
|
||||
|
||||
static IntPtr FindNotepadWindow()
|
||||
{
|
||||
IntPtr hwnd;
|
||||
|
||||
hwnd = NativeMethods.FindWindow(null, "Untitled - Notepad");
|
||||
if (hwnd != IntPtr.Zero)
|
||||
{
|
||||
return hwnd;
|
||||
}
|
||||
|
||||
hwnd = NativeMethods.FindWindow(null, "*Untitled - Notepad");
|
||||
if (hwnd != IntPtr.Zero)
|
||||
{
|
||||
return hwnd;
|
||||
}
|
||||
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
28
README.md
28
README.md
|
@ -1,7 +1,33 @@
|
|||
# Notepad.Extensions.Logging
|
||||
|
||||
[![NuGet](https://img.shields.io/nuget/v/Notepad.Extensions.Logging)](https://www.nuget.org/packages/Notepad.Extensions.Logging/)
|
||||
|
||||
This is a library for .NET / .NET Core to log your program's output to a handy Notepad window!
|
||||
|
||||
## Installation
|
||||
|
||||
To use:
|
||||
|
||||
1. Add a package reference to `Notepad.Extensions.Logging`.
|
||||
2. In `Startup.cs`, call `AddNotepad()`, like so:
|
||||
|
||||
```csharp
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddControllersWithViews();
|
||||
|
||||
// ...
|
||||
|
||||
services.AddLogging(lb => lb.AddNotepad()); // This is where the magic happens
|
||||
}
|
||||
```
|
||||
|
||||
3. Open a new Notepad window.
|
||||
4. Run your application.
|
||||
|
||||
## Source Material
|
||||
|
||||
Inspired by [this tweet](https://twitter.com/steveklabnik/status/1263190719721766918):
|
||||
|
||||
![](https://pbs.twimg.com/media/EYfBQ5cXsAEcu2e?format=jpg&name=orig)
|
||||
![](https://pbs.twimg.com/media/EYfBQ5cXsAEcu2e?format=jpg&name=orig)
|
||||
|
|
Loading…
Reference in a new issue