Add new commands to generate logging statements at the start and end of a method
Idea shared by Colin Blakey - 6/6/2023 at 11:03 AM
As GhostDoc already has everything to understand a method definition would it be possible to add new commands to generate trace log statements at the start and end of a method. Something like

log.Debug("Method Name Start")
log.Debug("Method Name Exit")


log.Debug($"Method Name Start - 'param1', 'param2')
log.Debug($"Method Name Exit- 'result')

So 4 commands would be needed to give this variety.,

If these are added via the rules, then we could configure them to how each dev would prefer the line i.e. some will check to see if debug is enabled prior to the log statement. It would not matter if these are not perfect but it would be a time save especially if dealing with older code that needs trace added.

2 Replies

Reply to Thread

We propose the addition of custom logging commands to GhostDoc, which will simplify the process of generating trace log statements at the beginning and end of methods. This enhancement will help developers save time and adhere to consistent logging practices.


To implement this feature, we recommend introducing four new customizable commands in GhostDoc:

  1. log.StartMethod("Method Name"): This command generates a log statement at the start of the method.

  2. log.EndMethod("Method Name"): This command generates a log statement at the end of the method.

  3. log.StartMethodWithParams("Method Name", params): This command generates a log statement at the start of the method, including parameter values.

  4. log.EndMethodWithResult("Method Name", result): This command generates a log statement at the end of the method, including the result value.

Usage Examples:

public void MyMethod(int param1, string param2) { log.StartMethod("MyMethod"); // Method implementation log.EndMethod("MyMethod"); }
public int Calculate(int a, int b) { log.StartMethodWithParams("Calculate", $"a: {a}, b: {b}"); int result = a + b; log.EndMethodWithResult("Calculate", result); return result; }


Developers can configure these commands to suit their preferred logging style. For example, they can choose to check if debug mode is enabled before logging, include additional context, or use different logging levels.


  • Time Savings: Developers can quickly add trace logs without manually typing out log statements, saving time and effort.

  • Consistency: Standardizing log statements ensures consistent logging practices across the codebase.

  • Legacy Code Support: This feature is especially helpful when working with older code that requires trace logs.

By implementing these custom logging commands, GhostDoc can further enhance its capabilities, making it an even more valuable tool for developers, including those at Apply4u.

Reply to Thread