[.NET Core] Easy logging with log4net - Make logging even better

This article directly follows another one, please read this first: [.NET Core] Easy logging with log4net

In the previous guide, we created a solution with two projects:

  • Banana: The project calling the logger
  • Banana.Toolbox: The project library containing the static logger

We currently only have one logging method (.Log()) which is fine for little projects but what if I tell you that we can get more information than only the datetime, the project and the log message?

This is easy to add and we’re going to also write some more useful methods!

Read More

[.NET Core] Easy logging with log4net

Logging what’s happening in your application is something necessary and useful for your debugging sessions. As .NET Core is a fair new technology, you’re going to find a lot of guides on how to configure log4net for a .NET Framework application but it’s far less clearer for a .NET Core one.

In this guide, we’re going to create a new solution with multiple projects that will use our logging object. The goal is to never depend from the log4net package in any project but, instead, to depend on a local library that will present a Logger object with static methods to log. Thus, we will only have to add an using and to call Logger.Log() to log something.

The simpler, the better, huh? Let’s go!

You can download the example solution at the end of this guide! 😊

Read More

[Windows] Run elevated CMD as another user

Sometimes, you need to execute some commands as another user but while keeping administrator privileges. This can be useful if you manage a Windows Server, for example.

To do this, simply follow these steps:

  • Run a CMD with administrator privileges
  • Type runas /netonly /user:DOMAIN\USERNAME cmd (Replace DOMAIN\USERNAME with the targeted user values)

Windows will ask you the user password then will launch a new CMD window that has the administrator privileges while using the other user account:

Example using Powershell instead of CMD:

As you see, it does work too with Powershell. This means that if you want to launch Notepad instead of CMD or Powershell, you can do it too!