Click here to Skip to main content
15,444,824 members

Welcome to the Lounge


For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

GeneralRe: Logging Pin
Matt Bond6-Jul-22 3:18
MemberMatt Bond6-Jul-22 3:18 
GeneralRe: Logging Pin
MikeCO106-Jul-22 3:26
MemberMikeCO106-Jul-22 3:26 
GeneralRe: Logging Pin
decaffeinatedMonkey6-Jul-22 3:56
MemberdecaffeinatedMonkey6-Jul-22 3:56 
GeneralRe: Logging Pin
MSBassSinger6-Jul-22 4:55
professionalMSBassSinger6-Jul-22 4:55 
GeneralRe: Logging Pin
Calin Cali6-Jul-22 5:40
MemberCalin Cali6-Jul-22 5:40 
GeneralRe: Logging Pin
MSBassSinger6-Jul-22 6:06
professionalMSBassSinger6-Jul-22 6:06 
GeneralRe: Logging Pin
Shmoken996-Jul-22 7:56
MemberShmoken996-Jul-22 7:56 
GeneralRe: Logging Pin
MSBassSinger6-Jul-22 7:28
professionalMSBassSinger6-Jul-22 7:28 
As far as design or process, this is my general pattern for logging. Of course, I also consider if any one or more of the steps is needed or not, or whether there is value in logging in any particular code block.
1 - On methods, use try-catch, and optionally, finally. Part of it is to ensure I log exceptions, and part of it is to destroy objects I create, given the GC may be slow to actually destroy the instance. The GC thing is a preference I have and a whole other discusssion.
2 - My logger gets the module and method names, as well as the line number so I can isolate where the problem occurred. It also captures the machine and usernames.
3 - My logger checks for inner exception instances to be sure to get all the exception messages.
4 - My log, when in a file, is tab delimited so it can be opened in Excel (or some other reader that handles columns). That aids in isolating specific repeating problems and doing analysis. The log to a SQL database table is easily queried from the same columns.
5 - My logging uses a bitset (flagged Enum) to categorize the log type. A bit comparison is used before logging so that if a particular log type is not "turned on", the call to the log is not made and that function overhead is not incurred. That also allows me to define what types to log in a config file, which can be changed at runtime to increase or decrease logging.
6 - My logger uses a queue approach, so that log entries are made to the queue (very fast, non-blocking, works great in multithreaded environments where there could be thousands of log entries from multiple parallel tasks). A separate task unwinds the FIFO queue to the written log or database (whichever is chosen). On shutdown, the queue is emptied before the logger shuts down.
7 - The logger creates a set of initial entries that capture system state, such as RAM, ethernet ports, disk space, OS and .NET info, etc. That has proven to be useful in figuring out problems related to the environment.
8 - I can include performance measurement for each method, and the code for it does not execute unless the performance bit is turned on in the log type bitset. Same for auditing flow in the log.
9 - I can optionally have a log entry send an email.
10 - If there is a practical need, I can add user-defined columns to my log (file or DB).
11 - I use the Exception.Data collection to store name-value pairs of runtime values that are useful in understanding the state at the time of the exception, and then logged. More than once, I have seen a value captured that immediately told me what the problem was (usually some missing validation on the front end).

Every developer is different in how they do things, and why. My approach has been refined over the decades to minimize the time spent during QA and during the post-production support part of the SDLC. If a given approach works for you, then it is the right approach.
GeneralWSO CCC OTD 2022-07-04 Pin
OriginalGriff3-Jul-22 21:41
mveOriginalGriff3-Jul-22 21:41 
GeneralRe: WSO CCC OTD 2022-07-04 Pin
pkfox3-Jul-22 22:12
professionalpkfox3-Jul-22 22:12 
GeneralRe: WSO CCC OTD 2022-07-04 - we have a winner! Pin
OriginalGriff3-Jul-22 22:49
mveOriginalGriff3-Jul-22 22:49 
GeneralRe: WSO CCC OTD 2022-07-04 - we have a winner! Pin
pkfox3-Jul-22 22:58
professionalpkfox3-Jul-22 22:58 
GeneralCCC Today ? Pin
pkfox3-Jul-22 20:03
professionalpkfox3-Jul-22 20:03 
GeneralRe: CCC Today ? Pin
OriginalGriff3-Jul-22 20:35
mveOriginalGriff3-Jul-22 20:35 
GeneralWordle 380 Pin
Amarnath S3-Jul-22 17:46
professionalAmarnath S3-Jul-22 17:46 
GeneralRe: Wordle 380 Pin
OriginalGriff3-Jul-22 19:00
mveOriginalGriff3-Jul-22 19:00 
GeneralRe: Wordle 380 Pin
Peter_in_27803-Jul-22 19:20
professionalPeter_in_27803-Jul-22 19:20 
GeneralRe: Wordle 380 - 3 for me Pin
pkfox3-Jul-22 19:47
professionalpkfox3-Jul-22 19:47 
GeneralRe: Wordle 380 Pin
0x01AA3-Jul-22 20:07
professional0x01AA3-Jul-22 20:07 
GeneralRe: Wordle 380 Pin
ChandraRam3-Jul-22 20:16
MemberChandraRam3-Jul-22 20:16 
GeneralRe: Wordle 380 Pin
den2k883-Jul-22 21:23
professionalden2k883-Jul-22 21:23 
GeneralRe: Wordle 380 Pin
Sander Rossel3-Jul-22 21:31
professionalSander Rossel3-Jul-22 21:31 
GeneralRe: Wordle 380 (3/6) Pin
musefan3-Jul-22 23:46
Membermusefan3-Jul-22 23:46 
GeneralRe: Wordle 380 Pin
Greg Utas4-Jul-22 0:18
mveGreg Utas4-Jul-22 0:18 
GeneralRe: Wordle 380 Pin
Cp-Coder4-Jul-22 4:12
MemberCp-Coder4-Jul-22 4:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Straw Poll

What topics would you like to learn more about?
Contributed by Marc Clifton.
  Results   6,523 votes