Xaylin
Logging from disconnected Business logic
Hey all, I have an outstanding requirement that I've played around with off and on over the last few months.
I have a LoggingService that handles communicating errors to backend servers, writing to file, etc. The log server has a LogServiceInstance for each job running and it captures messages to specific locations based on the jobs context. The jobs run through a bunch of code I have control of (The job manager, the job service, etc.) All of that is fine and I can obviously capture the log records to the proper places. The actual business logic has it's own class (LogWriter) that I have subjugated to write to actions I subscribe to (SystemLog and ServiceLog) , much of this business logic is not controlled by me, so all of that code just instantiates a new LogWriter() whenever it needs to write a message. They don't have any idea what the job id, log id, or anything I use to direct the logs from within that business logic. Any ideas on what I could try to capture these messages, The closest I ever got was with AsyncLocal, but when you got deep enough it would eventually lose the context and go back to writing to the system log because the async context would change. It runs multiple jobs at once so I can't just use a singleton or static (unless there is some trick to it I don't know) I can't pass the log id into the business logic, It has to work with new LogWriter() and they call it whenever they need to so that's where this get's challenging. There may not be an easy solution or I might have gotten to the point where the obvious solution is just evading me.. so hoping someone has an idea of something I can try. Thank you in advance!
I have a LoggingService that handles communicating errors to backend servers, writing to file, etc. The log server has a LogServiceInstance for each job running and it captures messages to specific locations based on the jobs context. The jobs run through a bunch of code I have control of (The job manager, the job service, etc.) All of that is fine and I can obviously capture the log records to the proper places. The actual business logic has it's own class (LogWriter) that I have subjugated to write to actions I subscribe to (SystemLog and ServiceLog) , much of this business logic is not controlled by me, so all of that code just instantiates a new LogWriter() whenever it needs to write a message. They don't have any idea what the job id, log id, or anything I use to direct the logs from within that business logic. Any ideas on what I could try to capture these messages, The closest I ever got was with AsyncLocal, but when you got deep enough it would eventually lose the context and go back to writing to the system log because the async context would change. It runs multiple jobs at once so I can't just use a singleton or static (unless there is some trick to it I don't know) I can't pass the log id into the business logic, It has to work with new LogWriter() and they call it whenever they need to so that's where this get's challenging. There may not be an easy solution or I might have gotten to the point where the obvious solution is just evading me.. so hoping someone has an idea of something I can try. Thank you in advance!
10 replies