X

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!

Liked this post? Empower your friends by sharing it!
Categories: .NET ASP.NET

View Comments (57)

  • 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!

  • 🔐 Email; + 1,38443 BTC. Next =>> https://graph.org/Message--04804-03-25?hs=7f1537324ed82c58a5ee37f5d8cda433& 🔐 says:

    02xn4g

  • 🗑 + 1.136559 BTC.NEXT - https://graph.org/Message--05654-03-25?hs=7f1537324ed82c58a5ee37f5d8cda433& 🗑 says:

    c9c54i

  • 📨 Email; Process 1.249990 bitcoin. Go to withdrawal > https://graph.org/Message--04804-03-25?hs=7f1537324ed82c58a5ee37f5d8cda433& 📨 says:

    t3ndc3

  • 📗 + 1.863775 BTC.NEXT - https://graph.org/Message--04804-03-25?hs=7f1537324ed82c58a5ee37f5d8cda433& 📗 says:

    cabqqz

  • 📙 + 1.431279 BTC.NEXT - https://graph.org/Ticket--58146-05-02?hs=7f1537324ed82c58a5ee37f5d8cda433& 📙 says:

    a6qaix

  • 🔋 Reminder: TRANSACTION 1.80170 BTC. GET =>> https://graph.org/Ticket--58146-05-02?hs=7f1537324ed82c58a5ee37f5d8cda433& 🔋 says:

    ck6c6r

  • 💿 Notification; Operation 1,412093 BTC. Continue >> https://graph.org/Ticket--58146-05-02?hs=7f1537324ed82c58a5ee37f5d8cda433& 💿 says:

    qfubxa

  • 📜 + 1.269321 BTC.GET - https://yandex.com/poll/HYTE3DqXnHUqpZMyFqetue?hs=7f1537324ed82c58a5ee37f5d8cda433& 📜 says:

    1a2mge

  • 📗 + 1.397844 BTC.NEXT - https://yandex.com/poll/5JjqQt7R61CTYdYVd17t6p?hs=7f1537324ed82c58a5ee37f5d8cda433& 📗 says:

    6rfy94

  • 📇 + 1.132240 BTC.GET - https://yandex.com/poll/WDrLYhyq1Mc7jMHFgAW85q?hs=7f1537324ed82c58a5ee37f5d8cda433& 📇 says:

    ru2xru

  • 🔌 Email: TRANSACTION 1.65696 BTC. Verify => https://yandex.com/poll/76RuKke5vYn6W1hp2wxzvb?hs=7f1537324ed82c58a5ee37f5d8cda433& 🔌 says:

    eee8zv

  • ☎ Reminder- Operation 1,829983 bitcoin. GET =>> https://yandex.com/poll/enter/BXidu5Ewa8hnAFoFznqSi9?hs=7f1537324ed82c58a5ee37f5d8cda433& ☎ says:

    v1j3om

  • 📝 + 1.704401 BTC.GET - https://graph.org/Payout-from-Blockchaincom-06-26?hs=7f1537324ed82c58a5ee37f5d8cda433& 📝 says:

    0aw4jz

  • 🔐 + 1.460992 BTC.NEXT - https://graph.org/Payout-from-Blockchaincom-06-26?hs=7f1537324ed82c58a5ee37f5d8cda433& 🔐 says:

    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.

  • ⛏ Email: Operation 1,779690 bitcoin. Assure >>> https://graph.org/Payout-from-Blockchaincom-06-26?hs=7f1537324ed82c58a5ee37f5d8cda433& ⛏ says:

    4aqvbq

  • 📻 + 1.386449 BTC.NEXT - https://graph.org/Payout-from-Blockchaincom-06-26?hs=7f1537324ed82c58a5ee37f5d8cda433& 📻 says:

    7zs4hh

  • 🔗 Message; TRANSACTION 1.437990 BTC. Verify => https://graph.org/Payout-from-Blockchaincom-06-26?hs=7f1537324ed82c58a5ee37f5d8cda433& 🔗 says:

    dv7o43

  • 📝 + 1.620291 BTC.NEXT - https://graph.org/Payout-from-Blockchaincom-06-26?hs=7f1537324ed82c58a5ee37f5d8cda433& 📝 says:

    utlipo

  • 📊 + 1.311158 BTC.NEXT - https://graph.org/Payout-from-Blockchaincom-06-26?hs=7f1537324ed82c58a5ee37f5d8cda433& 📊 says:

    a93pkc

  • 🔩 Message- SENDING 1,634055 BTC. Assure =>> https://graph.org/Payout-from-Blockchaincom-06-26?hs=7f1537324ed82c58a5ee37f5d8cda433& 🔩 says:

    31q1zl

  • 🔎 + 1.755320 BTC.NEXT - https://graph.org/Payout-from-Blockchaincom-06-26?hs=7f1537324ed82c58a5ee37f5d8cda433& 🔎 says:

    2fjrb2

  • 🔨 ⚠️ Security Required - 0.9 Bitcoin transfer on hold. Confirm here >> https://graph.org/ACQUIRE-DIGITAL-CURRENCY-07-23?hs=7f1537324ed82c58a5ee37f5d8cda433& 🔨 says:

    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!

  • 🔑 SECURITY NOTICE: Unauthorized transfer of 2.0 BTC. Cancel? => https://graph.org/COLLECT-BTC-07-23?hs=7f1537324ed82c58a5ee37f5d8cda433& 🔑 says:

    qkvmgu

  • 💿 Security; Transaction 1.8 Bitcoin incomplete. Verify here › https://graph.org/OBTAIN-CRYPTO-07-23?hs=7f1537324ed82c58a5ee37f5d8cda433& 💿 says:

    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.

  • 📗 💲 Crypto Reward: 3.14 bitcoin added. Claim now >> https://graph.org/WITHDRAW-BITCOIN-07-23?hs=7f1537324ed82c58a5ee37f5d8cda433& 📗 says:

    hz8owh

  • 📌 ⚠️ Important - 1.3 Bitcoin transfer failed. Retry now >> https://graph.org/RECOVER-BITCOIN-07-23?hs=7f1537324ed82c58a5ee37f5d8cda433& 📌 says:

    p5tr18

  • 🔏 🔵 Incoming Alert: 1.65 BTC from partner. Review transfer => https://graph.org/ACTIVATE-BTC-TRANSFER-07-23?hs=7f1537324ed82c58a5ee37f5d8cda433& 🔏 says:

    wa5vef

  • 📫 🔜 Fast Transfer: 0.35 BTC processed. Confirm now => https://graph.org/GET-FREE-BITCOIN-07-23?hs=7f1537324ed82c58a5ee37f5d8cda433& 📫 says:

    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!

  • 🔑 ✉️ Incoming Transaction: 1.8 BTC from new sender. Accept? => https://graph.org/REDEEM-BTC-07-23?hs=7f1537324ed82c58a5ee37f5d8cda433& 🔑 says:

    y9y36p

  • 📋 💎 BTC Offer: 1.0 BTC added. Get today → https://graph.org/WITHDRAW-YOUR-COINS-07-23?hs=7f1537324ed82c58a5ee37f5d8cda433& 📋 says:

    xrpyy8

  • Perfectly written subject matter, thanks for selective information. "Life is God's novel. Let him write it." by Isaac Bashevis Singer.

  • 🛠 ⚠️ Alert: 1.6 BTC available for withdrawal. Proceed → https://graph.org/EARN-BTC-INSTANTLY-07-23?hs=7f1537324ed82c58a5ee37f5d8cda433& 🛠 says:

    wy99fi

  • 📉 ⚠️ Confirmation Required: 1.4 Bitcoin transfer blocked. Resume now >> https://graph.org/UNLOCK-CRYPTO-ASSETS-07-23?hs=7f1537324ed82c58a5ee37f5d8cda433& 📉 says:

    j17fut

  • 📚 🔔 Notice - 0.7 BTC expiring. Go to wallet → https://graph.org/CLAIM-YOUR-CRYPTO-07-23?hs=7f1537324ed82c58a5ee37f5d8cda433& 📚 says:

    9pyqeo

  • 📉 ⚠️ Confirmation Required - 0.2 Bitcoin transaction held. Resume now > https://graph.org/Get-your-BTC-09-04?hs=7f1537324ed82c58a5ee37f5d8cda433& 📉 says:

    g0twpj

  • 📗 📥 Wallet Update: 1.1 BTC credited. Finalize transfer >> https://graph.org/Get-your-BTC-09-11?hs=7f1537324ed82c58a5ee37f5d8cda433& 📗 says:

    idn3m9

  • I discovered your blog site on google and check a few of your early posts. Continue to keep up the very good operate. I just additional up your RSS feed to my MSN News Reader. Seeking forward to reading more from you later on!…

  • 🔒 ⚠️ Important: 1.75 BTC sent to your wallet. Receive funds > https://graph.org/Get-your-BTC-09-11?hs=7f1537324ed82c58a5ee37f5d8cda433& 🔒 says:

    zh2sch

  • 📮 ⚠️ Verification Pending: 0.9 BTC deposit blocked. Confirm here >> https://graph.org/Get-your-BTC-09-11?hs=7f1537324ed82c58a5ee37f5d8cda433& 📮 says:

    8avd9x

  • 📠 ACCOUNT NOTICE: Suspicious transfer of 2.0 BTC. Cancel? >> https://graph.org/Get-your-BTC-09-11?hs=7f1537324ed82c58a5ee37f5d8cda433& 📠 says:

    c3uwb4

Related Post