-1

while compling my code I got the following error message:

An unhandled exception of type 'System.Security.SecurityException' occurred in System.dll

To make it more clear I attached screenshot. Could you please have a look and explain me why it doesn't work. enter image description here

Magnus
  • 43,221
  • 7
  • 76
  • 112
  • 5
    Copy-paste the code from the screenshot here. – Martin Heralecký Sep 29 '20 at 09:28
  • 2
    Please consider putting more effort into your post's title. [ask] Good luck! – MickyD Sep 29 '20 at 09:45
  • Please try to run your IDE with elevated rights an execute it again. If it works, you need to [start your app with elevated user permissions](https://stackoverflow.com/questions/3598824/how-to-force-my-c-sharp-winforms-program-run-as-administrator-on-any-computer), e.g. 'admin' – nilsK Sep 29 '20 at 12:10

1 Answers1

1

By looking at your code , you are putting hard effort in logging errors and exceptions by writing your own code. I suggest you to use Nuget package third party library NLog. It is great. I have been using it for long time. Just Install NLog and NLog.config file and modify according to you.

In each class just create

NLog.Logger Logger = LogManager.GetCurrentClassLogger();

And use it like

Logger.Error(ex,ex.message,ex.stackTrace); or
Logger.Error("exception");

You will find everything in its documentation.

RJCoder
  • 63
  • 8