Any clue how to use Topshelf.Logging
properly?
Do I have to pass NLogLogWriter
to the constructor of the service class?
And how to enable output to console as well?
class Program
{
#region Properties
Topshelf.Logging.NLogLogWriter logger;
static string mainLoggerName = "MainLogger";
#endregion
static void Main(string[] args)
{
var nlogLogger = LogManager.GetCurrentClassLogger();
Topshelf.Logging.NLogLogWriter logger = new Topshelf.Logging.NLogLogWriter(nlogLogger, mainLoggerName);
HostFactory.Run(x =>
{
x.Service<ExSPCAgentService>(s =>
{
s.ConstructUsing(name => new MyAgentService());
// s.WhenStarted(tc => tc.Start());
s.WhenStarted(tc =>
{
// Add more config options if you need
tc.Start();
});
s.WhenStopped(tc => tc.Stop());
});
x.RunAsLocalSystem();
x.UseNLog();
x.SetDescription("MyAgentService");
x.SetDisplayName("MyAgentService");
x.SetServiceName("MyAgentService");
});
}
}