© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•15mo ago•
9 replies
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!

//This is the default fallback action and always works
        public static event Action<string, string?>? SystemTraceMessage;
//This works when I have control to subscribe to it, but I don't deep within the business logic.
        public event Action<string, string>? SendTraceMessage;
//This is the default fallback action and always works
        public static event Action<string, string?>? SystemTraceMessage;
//This works when I have control to subscribe to it, but I don't deep within the business logic.
        public event Action<string, string>? SendTraceMessage;
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Business Logic Problem
C#CC# / help
14mo ago
❔ Business Logic Validation in Service Layer
C#CC# / help
3y ago
How to bind REST API and business logic ?
C#CC# / help
2y ago
Removing Logging Abstractions from Libraries
C#CC# / help
2y ago