In our Common Project we have all the interfaces. This includes where we define the interfaces for the HF jobs.
In the same name space as the Interfaces for the HF jobs we added
public interface IMyProjectBackgroundLogging
{
void SendToLog(string LogMessage);
}
Then in the Business logic project we added this method to the class to every service that we wanted to add logging to. So this code is at the top of each class after init.
private void SendToLogger(IMyProjectBackgroundLogging _LoggingObject, string LogMessage)
{
if (_LoggingObject != null)
{
_LoggingObject.SendToLog(LogMessage);
}
}
Then When we wanted to record something back to the HF.Console from with in the Business Logic. we updated the Method signature
void SomeBusinessMethod(string someValue, IMyProjectBackgroundLogging _LoggingObject = null)
{
SendToLogger(_LoggingObject, $"someValue = {someValue} ");
// other business logic in here
}
Then in side our HF web service We created the class to actually write to the HF.Console.
public class HFConsoleLogger : IMyProjectBackgroundLogging
{
private PerformContext _currentContext;
public void SendToLog(string LogMessage)
{
if(_currentContext!= null)
{
_currentContext.WriteLine(LogMessage);
}
}
public PerformContext currentContext
{
get { return _currentContext; }
set
{
_currentContext = value;
}
}
}
Then When the HF job runs at the top of the method for the job we put
HFConsoleLogger _localCL = new HFConsoleLogger();
_localCL.currentContext = context;
// then call the Business logic method to perform background task and pass the _localCL
myBusinessLogicClass.SomeBusinessMethod(“why so serious?”, _localCL)
By adding “IMyProjectBackgroundLogging _LoggingObject = null” to the method signature, we didn’t break any existing calls to the business logic as the parameter is optional.
Sorry this probably looks like a hot mess here on a message board but thats how we accomplished the task.
Let me know if you have any questions.