Are there any options other than using preprocessor directives to enable / disable logging depending on the environment variable? I don't want sensitive data from the production environment to go into the logs. So it turns out that each environment will have its own configuration.
public class Service
{
private readonly Serilog.ILogger logger;
public Service(ILogger logger)
{
this.logger = logger;
}
public void DoSomething()
{
#if DEBUG
// if it's a development environment
this.logger
.ForContext("Debug data", data)
.Information("something happened");
#endif
// if it's a production environment
this.logger.Information("something happened");
}
}