I'm performing a cleanup of the database in my code. It looks as follows:
#region Orders and SubOrders
try
{
... // this code tries to remove the Orders and the SubOrders
}
catch (Exception ex)
{
_logger.Error($"An exception occurred while cleaning Orders and SubOrders. Error message=[{ex.Message}]");
}
#region Customers
try
{
... // this code tries to remove the Customers
}
catch (Exception ex)
{
_logger.Error($"An exception occurred while cleaning Customers. Error message=[{ex.Message}]");
}
Is it possible to replace the _logger line by something like:
_logger.Error($"An exception occurred while cleaning [{#currentregion}]. Error message=[{ex.Message}]");
Thanks in advance
No you can't. In C#, the #region directive is a feature of the C# preprocessor that allows you to group sections of code for organizational purposes in the editor, but it doesn't have any runtime presence. Once your code is compiled, the #region directives are not preserved in the compiled binary