Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 720145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:43:30+00:00 2026-05-14T05:43:30+00:00

public void EatDinner(string appetizer, string mainCourse, string dessert) { try { // Code }

  • 0
public void EatDinner(string appetizer, string mainCourse, string dessert)
{
   try
   {
      // Code
   }
   catch (Exception ex)
   {
      Logger.Log("Error in EatDinner", ex);
      return;
   }
}

When an exception occurs in a specific method, what should I be logging?

I see a lot of the above in the code I work with. In these cases, I always have to talk to the person who experienced the error to find out what they were doing, step through the code, and try to reproduce the error.

Is there any best practices or ways I can minimize all this extra work? Should I log the parameters in each method like this?

Logger.Log("Params: " + appetizer + "," + mainCourse + "," + dessert, ex);

Is there a better way to log the current environment? If I do it this way, will I need to write out all this stuff for each method I have in my application? Are there any best practices concerning scenarios like this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:43:30+00:00Added an answer on May 14, 2026 at 5:43 am

    As a general rule, I would say strive to log all the information necessary to reproduce the course of events leading to an error. Note that you don’t necessarily need to log everything inside the catch block: you can put (debug) log statements around in your code, inside methods called etc. which enable you to follow what was going on directly before the exception. Also, you should put information into the exception itself about the exact symptom what caused it.

    IMHO going through all the code to add log statements everywhere may be overkill – or at the least, not cost effective in a real life project. Instead, focus on the most critical code parts to maximize returns from your efforts. These code parts are typically where the most bugs happen and/or the most modifications are (going to be) done. So in practice whenever you need to touch a piece of code, think about logging, check the log statements already present there (if there is any), check exception handling (if there is any – I routinely see not only code like your example which simply swallows the exception caught, but even empty or autogenerated catch blocks in our legacy code… all of these may leave the application in undefined state, which is a BAD THING), and think about whether what is already there is enough for you to reproduce failures and understand what happened if an error occurs. Then improve it as much as you need to and can with a reasonable effort.

    It also helps to discuss this topic with your teammates and try to work out a rough project convention of how to log events, how to handle exceptions etc. This might save you a lot of time otherwise spent on chasing bugs and/or improving code produced by your very coworkers 🙁

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public void log(String msg, Color c = Color.black) { loggerText.ForeColor = c; loggerText.AppendText(\n +
public void populateNotesFromFile() { try{ BufferedReader reader = new BufferedReader(new FileReader(DEFAULT_NOTES_SAVED)); String fileNotes =
public void CreateVirtualDirectory(string nameDirectory, string realPath) { System.DirectoryServices.DirectoryEntry oDE; System.DirectoryServices.DirectoryEntries oDC; System.DirectoryServices.DirectoryEntry oVirDir; try
public void GrabData() throws IOException { try { BufferedReader br = new BufferedReader(new FileReader(data/500.txt));
public void EditAndSave(String fileName) { Bitmap b = new Bitmap(fileName); /** * Edit bitmap
public void valueChanged(TreeSelectionEvent event) { //Add images depending on selection. String selection = navigation.getLastSelectedPathComponent().toString();
public void AddNodeToXml(string helpid, string fileName) { const string STR_EXPRESSION = /Form/Controls/Control; XPathDocument doc
public void button2_Click(object sender, System.EventArgs e) { string text = textBox1.Text; Mainform = this;
public void DoRiskyThings(List<Action> tasks) { List<Exception> exceptions = new List<Exception>(); foreach(Action task in tasks)
public void RestoreDatabase(String databaseName, String filePath, String serverName, String userName, String password, String dataFilePath,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.