Chr*_*ian 0 c# mono service debian daemon
我似乎无法找到一种方法让一个C#服务作为debian中的"服务"运行.我究竟做错了什么?
我跟着这个帖子从MSDN创建一个样本窗口服务:http://msdn.microsoft.com/en-us/library/zt39148a(v=vs.80).aspx
我可以在我的Windows机器上运行该服务,启动和停止服务,并看到它写入MyNewLog.
然后我将它(.exe文件)复制到我的debian机器并尝试使用(作为root)mono-service MyNewService.exe运行它
Syslog告诉我,服务已经开始了!
我没有错误,我在系统中看不到任何新创建的日志文件.我究竟做错了什么?
如果有帮助,这里是代码:Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
namespace MyNewService
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[]
{
new MyNewService()
};
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
}
}
Run Code Online (Sandbox Code Playgroud)
Service.cs
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 MyNewService
{
public partial class MyNewService : ServiceBase
{
public MyNewService()
{
InitializeComponent();
if (!System.Diagnostics.EventLog.SourceExists("MySource"))
{
System.Diagnostics.EventLog.CreateEventSource(
"MySource", "MyNewLog");
}
myEventLog.Source = "MySource";
myEventLog.Log = "MyNewLog";
}
protected override void OnStart(string[] args)
{
myEventLog.WriteEntry("Service Started: OnStart");
}
protected override void OnStop()
{
myEventLog.WriteEntry("Service Halted: OnStop.");
}
}
}
Run Code Online (Sandbox Code Playgroud)
/干杯