如何在LocalSystem服务中使用loggly?

时间:2018-10-17 13:05:02

标签: c# wcf service loggly

我有一个名为“ CameraManagerService”的LocalSystem服务,定义如下:

public partial class CameraManagerService : ServiceBase
{
    private ServiceHost serviceHost = null;

    public ESCCameraManagerService()
    {
        InitializeComponent();
        ServiceName = "CameraManagerService";
    }

    protected override void OnStart(string[] args)
    {
        if (serviceHost != null)
        {
            serviceHost.Close();
        }
        serviceHost = new ServiceHost(typeof(CameraManager));
        serviceHost.Open();
    }

    protected override void OnStop()
    {
        if (serviceHost != null)
        {
            serviceHost.Close();
            serviceHost = null;
        }
    }

以及随附的App.config文件定义如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="log4net" 
    type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>

<appSettings>
  <add key="AppName" value="CameraService" />
  <add key="LogglyToken" value="56c1671c-5585-1672-9d9e-4f913346671e" />
  <add key="LogglyTag" value="log4net" />
  <add key="LogglyRootUrl" value="https://logs-01.loggly.com/" />
</appSettings>

<log4net>
<root>
  <level value="ALL" />
  <appender-ref ref="LogglyAppender" />
  <appender-ref ref="LogFileAppender" />
</root>
<appender name="LogglyAppender" type="log4net.loggly.LogglyAppender, log4net-loggly">
  <rootUrl value="https://logs-01.loggly.com/" />
  <inputKey value="56c1671c-5585-1672-9d9e-4f913346671e" />
  <tag value="log4net" />
</appender>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
  <param name="File" value="C:\ESC3-Logs\Logs_CameraService.json" />
  <param name="AppendToFile" value="true" />
  <rollingStyle value="Size" />
  <maxSizeRollBackups value="10" />
  <maximumFileSize value="10MB" />
  <staticLogFileName value="true" />
  <layout type="log4net.Layout.SerializedLayout, log4net.Ext.Json">
    <decorator type="log4net.Layout.Decorators.StandardTypesDecorator, log4net.Ext.Json" />
    <default />
    <remove value="message" />
    <arrangement value="Post:messageobject" />
    <arrangement value="Host=Name:hostname" />
    <member value="" />
  </layout>
</appender>
</log4net>

我已经下载了log4net,log4net.Ext.json和log4net-loggly的软件包。

我可以轻松登录文件

  

“ C:\ ESC3-Logs \ Logs_CameraService.json”

但是我看不到日志记录。

对于其他非服务项目,我具有相同的日志记录配置,并且可以毫无问题地使用loggly。

在尝试登录服务时,还需要执行其他操作以登录本地系统吗?

0 个答案:

没有答案