Skip to content

Instantly share code, notes, and snippets.

@droyad
Last active January 16, 2018 22:56
Show Gist options
  • Save droyad/6d0cf8b88d3d55df6ae83a325290aa9d to your computer and use it in GitHub Desktop.
Save droyad/6d0cf8b88d3d55df6ae83a325290aa9d to your computer and use it in GitHub Desktop.
LibLog logger
void Main()
{
Halibut.Logging.LogProvider.SetCurrentLogProvider(new ConsoleLogProvider());
var rt = new HalibutRuntime(new X509Certificate2());
rt.Poll(new Uri("http://example.com"), new ServiceEndPoint("http://example.com", ""));
Thread.Sleep(10000);
}
class ConsoleLogProvider : Halibut.Logging.ILogProvider
{
public Logger GetLogger(string name) => new ConsoleLogger(name).Log;
public IDisposable OpenMappedContext(string key, string value) => null;
public IDisposable OpenNestedContext(string message) => null;
public class ConsoleLogger
{
string _name;
public ConsoleLogger(string name)
{
_name = name;
}
public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception = null, params object[] formatParameters)
{
Console.WriteLine($"From: {_name}, Message: {string.Format(messageFunc(), formatParameters)}");
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment