How to remove the stacktrace from the standard Ser

2019-07-22 20:33发布

问题:

I'm just getting started with ServiceStack, and I'd like to find out if it's possible to remove the stacktrace from the standard error response.

I have tried shutting off debugmode without any luck:

public override void Configure(Funq.Container container)
{
    SetConfig(new EndpointHostConfig { DebugMode = false, });
}

Thanks a bunch!

回答1:

By default the configuration below only removes the StackTrace from being externally visible in your Web Service's response:

SetConfig(new EndpointHostConfig { DebugMode = false, });

I've tested this again and it works as expected.

To disable Logging all together you can set ServiceStack to use a NullLogFactory

LogManager.LogFactory = new NullLogFactory();

Alternatively you can control the granularity of all logging by creating your own ServiceStack.Logging adapter and setting it in the same way:

LogManager.LogFactory = new MyCustomLogFactory();


回答2:

I was worried about the stack trace before and did some testing about it.

I found out that in the default case you don't need to set this option. If the project is built in Release then the stack trace is not in the response.