Skip to content

Instantly share code, notes, and snippets.

@aggieben
Created July 8, 2012 22:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aggieben/3073339 to your computer and use it in GitHub Desktop.
Save aggieben/3073339 to your computer and use it in GitHub Desktop.
Skeletal Windows Service which blocks on NLog
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target xsi:type="Debugger" name="debugger_target" />
<target xsi:type="Chainsaw" name="chainsaw_target" address="udp4://localhost:4141"/>
<!--
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
-->
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="chainsaw_target"/>
</rules>
</nlog>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
namespace WindowsService1
{
public partial class Service1 : ServiceBase
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
logger.Trace("Service1 started.");
}
protected override void OnStop()
{
logger.Trace("Service1 stopped.");
}
}
}
@djonasdev
Copy link

This is not working on my App. Do you have any solutions for me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment