Excluding a particular log message

76 views
Skip to first unread message

paolo ponzano

unread,
Jan 8, 2016, 4:26:00 AM1/8/16
to Serilog
Hello,
I'm currently facing some troubles to skip logging keep alive message that the clients send to the server.
I don't know if you're familiar with ServiceStack but consider it as a simple HTTP request where client ask for a keep alive and it get a response

public class KeepAliveRequest : IReturn<KeepAliveResponse>
{
}

where the KeepAliveResponse is


public class KeepAliveResponse
    {
        public DateTime HeartBeat { get; set; }
 }

Now my server side log file looks like

2016-01-07 12:22:40.263 +01:00 [Debug] Logging request KeepAliveRequest {  }
2016-01-07 12:22:42.273 +01:00 [Debug] Logging request KeepAliveRequest {  }
2016-01-07 12:22:44.287 +01:00 [Debug] Logging request KeepAliveRequest {  }
2016-01-07 12:22:46.304 +01:00 [Debug] Logging request KeepAliveRequest {  }
2016-01-07 12:22:48.325 +01:00 [Debug] Logging request KeepAliveRequest {  }
2016-01-07 12:22:50.341 +01:00 [Debug] Logging request KeepAliveRequest {  }
2016-01-07 12:22:52.357 +01:00 [Debug] Logging request KeepAliveRequest {  }
2016-01-07 12:22:54.369 +01:00 [Debug] Logging request KeepAliveRequest {  }
2016-01-07 12:22:56.391 +01:00 [Debug] Logging request KeepAliveRequest {  }
2016-01-07 12:22:58.418 +01:00 [Debug] Logging request KeepAliveRequest {  }
2016-01-07 12:23:00.434 +01:00 [Debug] Logging request KeepAliveRequest {  }
2016-01-07 12:23:02.449 +01:00 [Debug] Logging request KeepAliveRequest {  }
2016-01-07 12:23:04.466 +01:00 [Debug] Logging request KeepAliveRequest {  }
2016-01-07 12:23:06.482 +01:00 [Debug] Logging request KeepAliveRequest {  }
2016-01-07 12:23:08.531 +01:00 [Debug] Logging request KeepAliveRequest {  }
2016-01-07 12:23:10.542 +01:00 [Debug] Logging request KeepAliveRequest {  }
2016-01-07 12:23:12.563 +01:00 [Debug] Logging request KeepAliveRequest {  }
2016-01-07 12:23:14.578 +01:00 [Debug] Logging request KeepAliveRequest {  }

I've created a KeepAlive Filter 

 public class KeepAliveFilter : ILogEventFilter
    {
        public bool IsEnabled(LogEvent logEvent)
        {
            int t = 0;

            return true;
        }
    }

But I don't know how to tell if the received message is

Consider that all the requested messages are processed by this method in the ServiceRunner class

public override object Execute(IRequest request, object instance, TRequest requestDto)
        {
            var username = request.Headers.Get(HeaderHelper.UserName);

            if (!string.IsNullOrEmpty(username))
            {
                using (LogContext.PushProperty(HeaderHelper.UserName, username))
                {
                    Serilog.Log.ForContext(instance.GetType()).Debug("Logging request {@Request}", requestDto);
                }
            }

            return base.Execute(request, instance, requestDto);
        }
Thanks


nblum...@nblumhardt.com

unread,
Jan 9, 2016, 5:40:53 AM1/9/16
to Serilog
Hi Paolo,

This might help get things started:

    public class KeepAliveFilter : ILogEventFilter
    {
        public bool IsEnabled(LogEvent logEvent)
        {
            LogEventPropertyValue p;
            if (logEvent.Properties.TryGetValue("Request", out p) && p is StructureValue)
                return ((StructureValue)p).TypeTag != "KeepAliveRequest";

            return true;
        }
    }

Cheers,
Nick
Reply all
Reply to author
Forward
0 new messages