2

Once logging is configured with

LogManager.LogFactory = new Log4NetFactory(configureLog4Net: true);

it can be used anywhere with

ILog log = LogManager.GetLogger("foo);
log.Error("foo");

I get it. The problem is that Service Stack uses the same logger for various built-in internal messages. For example, if request is submitted for a non-existing route, Service Stack logs "ServiceStack.Host.Handlers.NotFoundHttpHandler - ::1 Request not found:".

Is there a way to disable or turn off those internal messages?

Stan Bashtavenko
  • 1,025
  • 11
  • 16
  • Possible duplicate of [Turn Off ServiceStack Logging](http://stackoverflow.com/questions/18598391/turn-off-servicestack-logging) – PatrickSteele Jun 16 '16 at 22:29
  • http://stackoverflow.com/questions/18598391/turn-off-servicestack-logging turns off both SS internal and application logging. I still want my application to log, but suppress internal logging. I am checking @mythz solution. – Stan Bashtavenko Jun 17 '16 at 12:14
  • Did you read the comments for the accepted answer? It addressed that exact concern: `EndpointHostConfig.DebugMode = false`. – PatrickSteele Jun 17 '16 at 12:54
  • Yes, I tried "DebugMode = false" - didn't work. In NotFoundHttpHttpHandler (SS internal class) the log is created by private static readonly ILog Log = LogManager.GetLogger(typeof(NotFoundHttpHandler)); and then it simply used by Log.ErrorFormat("{0} Request not found: {1}", request.UserHostAddress, request.RawUrl); I don't see how flipping DebugMode would help in this situation. Note this isn't just that handler, there are many others like ServiceStack.Redis, for example. – Stan Bashtavenko Jun 17 '16 at 17:23
  • Thanks for the follow-up. The comment about setting `DebugMode = false` had an upvote so I was hoping it was a possible solution. You might want to consider adding a comment to the question I linked to indicating that setting the debug mode off doesn't disable logging. – PatrickSteele Jun 17 '16 at 20:44

1 Answers1

1

If you're using Log4Net you should be able to filter Log messages by type, otherwise some of ServiceStack's internal logging can be controlled in your AppHost by overriding:

public override void OnLogError(Type type, string message, Exception innerEx=null)
{
    if (!SuppressLogs(type))
        base.OnLogError(type, message, innerEx);
}

I've also just changed NotFoundHttpHandler to route messages to route error messages to OnLogError() from this commit so you'll be able to suppress messages by overriding the above method.

This change is available from v4.0.61 that's now available on MyGet.

Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390
  • Log4Net filter worked, thank you! Question on OnLogError - will it take care of ServiceStack.Redis.*, ServiceStack.OrmLite.*, ServiceStack.Dto*, and ServiceStack.Messaging* events as well? We have a ton of those. – Stan Bashtavenko Jun 20 '16 at 14:02
  • Yeah it should do, they follow the same logging patern – mythz Jun 20 '16 at 17:07