2

Is a possible to remove path from error message in Visual Studio 2017?

I use Visual Studio 2017 to write a Windows service and I use log4net for logging events.

log.ErrorFormat("Error TrafficManager: {0}", e);

Resulting output:

2019-08-05 15:26:05,713 [5] ERROR [Commander] - Error TrafficManager: {0}System.NullReferenceException: Object reference not set to an instance of an object.

at BSC_ScadaCommanderListener.Server.TrafficManager(Object sender) in c:\Users[name][folder_project][folder_project][folder_project][folder_project][folder_project]\Server.cs:line 424

ADyson
  • 57,178
  • 14
  • 51
  • 63
Cristian
  • 87
  • 3
  • 3
    Sure. It appears you know the format of the error, so it's basically string manipulation to remove some text. The question I have is - why would you want to? – mason Aug 05 '19 at 14:44
  • Possible duplicate of [Do not show file paths of build machine in stack trace](https://stackoverflow.com/questions/2139263/do-not-show-file-paths-of-build-machine-in-stack-trace) – div Aug 05 '19 at 14:46
  • 1
    Remove the pdb files. –  Aug 05 '19 at 14:48
  • @Amy Not only that, but the path to the pdb file is also bundled within the exe/dll. You have to recompile without any debug info for the paths to be completely striped out. You lose the ability to debug, though. – Alejandro Aug 05 '19 at 14:57
  • @mason because in this path are sensitive information and I can't change the path of project. I ask because I thinking if it is something in visual studio project settings for hide only the path. – Cristian Aug 05 '19 at 15:15
  • 1
    how is a folder name sensitive information, exactly? It's in the user's folder, so they can already see it. And it's unlikely they'd look at the logfile anyway. Who are you trying to hide the information from, and why? – ADyson Aug 05 '19 at 15:17
  • If you consider those paths sensitive, consider that they're part of the .pdb files that you're probably shipping along with the application. If just the username is considered sensitive, then perhaps you should build the project out of a folder that doesn't contain a username. – mason Aug 05 '19 at 15:20
  • @ADyson yes it's in the user's folder but this is the problem, the name of folder is an email address. Exist a setting in visual studio 2017 that could hide the path? – Cristian Aug 05 '19 at 15:33
  • It's nothing to do with the product named Visual Studio, that's just an IDE. .NET code does not require Visual Studio to run. Now, I don't know log4Net but I would guess it may contain a way for you to change your error log format so that it doesn't output the stack trace (which is the part of the exception which contains the path). But you may find that it harder to diagnose problems if you can't see which line of code it occurred on. As far as I know there is no way to make the stack trace itself hide the path - normally it's considered important to know exactly which code caused the error! – ADyson Aug 05 '19 at 15:37
  • So...who are you trying to hide this from, exactly? Where does the error get logged? Is it inside the user's folder? And who looks at the logs? Normally a system administrator or developer sees "sensitive" data all day long, and they usually exempt from restrictions in this kind of area (and that's why you have good employment procedures so you hope you can trust your staff). So I see little point in hiding it from those people in general - they need the path in order to fix the problem. – ADyson Aug 05 '19 at 15:39
  • If it's really **so** sensitive you can't possibly output it, then as mentioned above, consider building the app outside the users folder, so that the path it reports is completely mundane. – ADyson Aug 05 '19 at 15:40
  • Or consider not including the pdb files in the build - this is often done in the production environment, and that will hide the exact location of the error, even though it does reduce the usefulness of the stack trace somewhat. See https://stackoverflow.com/questions/2139263/do-not-show-file-paths-of-build-machine-in-stack-trace – ADyson Aug 05 '19 at 15:43
  • 1
    It seems like your issue is with the username in the file path. So just build your code from a directory that doesn't use a file path. Simple. – mason Aug 05 '19 at 15:58
  • @ADyson it is a domain PC and use like user account email address with outlook. I think in SharpDevelop it is this possibility to hide the path from project settings. I don't want to wrong but I think is samthing about Symbol file (.pdb) locations. [link](https://devblogs.microsoft.com/devops/understanding-symbol-files-and-visual-studios-symbol-settings/) – Cristian Aug 05 '19 at 16:00
  • Yes I already mentioned that - see my previous comment. – ADyson Aug 05 '19 at 16:02
  • @mason yes this is an alternative but I thinking of it the possibility to hide or change path from project settings – Cristian Aug 05 '19 at 16:04

0 Answers0