Logging to Notepad window from ASP.NET Core
Something funny to end this week. When checking my Twitter feeds I found a kinky tweet about logging .NET Core messages to Notepad window. Yes, you heard right – .NET Core logger for Notepad. It’s not real, you want to say, but it is. And here’s how it works :)
The story of Notepad.Extensions.Logging
When checking Twitter I found a funny tweet by @yaakov_h where he announced NuGet package for .NET Core logger that targets Notepad. He got inspiration for this from tweet by @steveklabnik.
And guess what? Besides GitHub repository for Notepad.Extensions.Logging there’s also NuGet package available!
It’s a real deal – version 1.0.0, you see? :)
Notepad logger in action
Let’s get hands dirty with this little piece of art. Just create new ASP.NET Core web application and add Notepad.Extensions.Logging NuGet package. After this modify ConfigureServices() method in Startup like in following code fragment.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddLogging(lb => lb.AddNotepad());
}
To try things out I made my HomeController log some messages.
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
_logger.LogInformation("Home.Index opened");
return View();
}
public IActionResult Privacy()
{
_logger.LogInformation("Home.Privacy opened");
return View();
}
public override void OnActionExecuted(ActionExecutedContext context)
{
base.OnActionExecuted(context);
_logger.LogInformation("Action executed");
}
}
I didn’t made it work with NuGet package for some reason. I had to clone Notepad.Extensions.Logging repository to my machine and add it as project reference to web application. Then after few runs messages started appear to Notepad. Here’s the short video I made of this experiment.
So, it works after all!
Should I really use it?
Although this solution is funny it may still come handy when debugging something and there are things to dig out from logs frequently. It’s possible to disable all other log targets for debugging and skip logging related disk I/O as communication with Notepad goes directly through memory.
After using Notepad.Logging.Extensions few hours I actually started to like it. It’s weird but feels somehow convenient. Is Notepad the best choice for text editor? Who knows. But it’s not very hard to extend Notepad.Logging.Extensions to use some more advanced text editor.
Anyway, happy weekend and cheers!
Pingback:Dew Drop – May 22, 2020 (#3203) | Morning Dew
Pingback:The Morning Brew - Chris Alcock » The Morning Brew #3000
This actually has some cool possibilities. What I have always wanted is to have different types of output go to different output windows. Think Debug.Writeline(windowN,”message”)
That way all my SQL related stuff can go in 1, maybe stack trace stuff in another. That way I don’t have to sift through it too much if it’s already separated. Perhaps with this I can get something like that. Funny post, but sometimes the coolest things come stuff like this!
This is so cool! I might use this in production, to be honest.
I found many interesting implementations:
Rust – https://github.com/sgrif/notepad_logger
C# / Serilog – https://github.com/augustoproiete/serilog-sinks-notepad
Zig – https://github.com/Sobeston/notepad-stream/
Frida – https://github.com/FuzzySecurity/Fermion/blob/master/Examples/NotepadLogger.js
02xn4g
c9c54i
t3ndc3
cabqqz
a6qaix
ck6c6r
qfubxa
1a2mge
X7gmG8q6
6rfy94
ru2xru
eee8zv
v1j3om
555
ThISzGJ9
1*555
1′”
Test Pilot (film)
0aw4jz
555
555
ht5zDNJK
1
b1lsmd
Very good written post. It will be useful to anybody who employess it, including me. Keep up the good work – for sure i will check out more posts.
4aqvbq
7zs4hh
dv7o43
utlipo
a93pkc
31q1zl
2fjrb2
fnizlv
I do not even know how I ended up here, but I thought this post was great. I don’t know who you are but certainly you are going to a famous blogger if you are not already ;) Cheers!
qkvmgu
v9df3s
I do agree with all the ideas you have presented in your post. They are really convincing and will definitely work. Still, the posts are very short for beginners. Could you please extend them a little from next time? Thanks for the post.
pf56v6
hz8owh
p5tr18
wa5vef
g6vnvc
Having read this I thought it was very informative. I appreciate you taking the time and effort to put this article together. I once again find myself spending way to much time both reading and commenting. But so what, it was still worth it!
y9y36p
xrpyy8
Perfectly written subject matter, thanks for selective information. “Life is God’s novel. Let him write it.” by Isaac Bashevis Singer.
wy99fi
j17fut
9pyqeo
g0twpj
idn3m9