Is it better to log exception or exception.getMessage()while logging an info log or an error log. I'm pretty sure that is related to the context but I'd like to know from a technical perspective on which would be better for any application or if its all the same.
the error message itself is usually pointless. for all you know, some funny guy had code like this:
// code throwing whatever Exceptions
throw new Exception("This message is pointless");
throw new Exception("Huh ... didn't see this one coming");
Sure, you can print the error message, but what good 'll it do? I second James' advice: log the stacktrace. Not only does it tell what the underlying cause was, but it'll also tell you exactly what line(s) of your code to investigate.
But, in addition: I would recommend having several logging 'profiles':
Info (logging only informational messages), debug (logging all you need to debug your code), error (logging errors, and not just superficial), ...
this way, if a product has run for years without any single issue (well, I'm allowed to dream, right?) you might want to loosen what you log, so you don't get too large log files with tons of information you'll never even look at.
You wouldn't need it for info, and probably not for well-designed debug logs, but if you need to trace an error then it's near essential. It doesn't cost much, and then only when you actually have an Exception.
printStackTrace() is really valuable when debugging, but is not something you would typically do in a live production system for the reasons discussed in that link.
When logging in a live system, and when a fatal Exception occurs I would log everything that could be relevant, including the stack at the time, obtained from getStackTrace()
I Developed application in C# with crystal reports and created setup file in third party (Advance) Installer.When i installed my application on client system application is working but ...