Enable Event Logs on Your Server - marcos8154/SocketAppServer GitHub Wiki
Like any good framework, MobileAppServer allows you to capture event logs. To do this, create a class in your project that implements the "ILoggerWrapper" interface, located in the "MobileAppServer.ServerObjects" namespace:
public class MyLoggerWrapper : ILoggerWrapper
{
public List<ServerLog> List(Expression<Func<ServerLog, bool>> query)
{
throw new NotImplementedException();
}
public void Register(ServerLog log)
{
throw new NotImplementedException();
}
}
As you can see, the interface contains 2 methods: List and Register
The List method is so that you can provide log events from any repository of your choice. If this feature doesn't interest you, just leave the method untouched
The Register method is responsible for receiving all events from the server, as well as those triggered by your application. At this point you can persist these events in a repository of your choice for future audit.
You can fire logs to the server from the LogController class by invoking the WriteLog statistical method.
LogController.WriteLog(new ServerLog("My simple log text", ServerLogType.INFO));
As you have noted, it is necessary to pass WriteLog an instance of ServerLog, whose constructors are as follows:
//constructor #1
public ServerLog(string logText, ServerLogType type = ServerLogType.INFO)
//constructor #2
public ServerLog(string logText, string controller, string action, ServerLogType type = ServerLogType.INFO)
Just choose which builder best suits the scenario and pass the required parameters
As de prache, we must register our log class in the server instance, see below:
server.SetDefaultLoggerWrapper(new MyLoggerWrapper());