I have a c# project that is targeting net7.0. I have a block code that should only run when running on windows. And I am developing on Windows. To that end, I’ve added #if...#endif
#if WINDOWS
using var el = new EventLog("Application");
el.Source = "Application Error";
el.WriteEntry(ex.ToString(), EventLogEntryType.Error, 10002);
#endif
However, when I run it locally in Visual Studio 2022, the code inside the block is grayed out and does not run at all.
How do I mark it so that it only runs on windows?
6