Cleanse exceptions in event logs

(cherry picked from commit 404e6d68ea526ab521cd39ecda1bf3b02285765d)
pull/3723/head^2
Bogdan 3 months ago
parent b83a760873
commit c4f30da648

@ -57,33 +57,36 @@ namespace NzbDrone.Core.Instrumentation
{ {
try try
{ {
var log = new Log(); var log = new Log
log.Time = logEvent.TimeStamp; {
log.Message = CleanseLogMessage.Cleanse(logEvent.FormattedMessage); Time = logEvent.TimeStamp,
Logger = logEvent.LoggerName,
log.Logger = logEvent.LoggerName; Level = logEvent.Level.Name
};
if (log.Logger.StartsWith("NzbDrone.")) if (log.Logger.StartsWith("NzbDrone."))
{ {
log.Logger = log.Logger.Remove(0, 9); log.Logger = log.Logger.Remove(0, 9);
} }
var message = logEvent.FormattedMessage;
if (logEvent.Exception != null) if (logEvent.Exception != null)
{ {
if (string.IsNullOrWhiteSpace(log.Message)) if (string.IsNullOrWhiteSpace(message))
{ {
log.Message = logEvent.Exception.Message; message = logEvent.Exception.Message;
} }
else else
{ {
log.Message += ": " + logEvent.Exception.Message; message += ": " + logEvent.Exception.Message;
} }
log.Exception = logEvent.Exception.ToString(); log.Exception = CleanseLogMessage.Cleanse(logEvent.Exception.ToString());
log.ExceptionType = logEvent.Exception.GetType().ToString(); log.ExceptionType = logEvent.Exception.GetType().ToString();
} }
log.Level = logEvent.Level.Name; log.Message = CleanseLogMessage.Cleanse(message);
var connectionInfo = _connectionStringFactory.LogDbConnection; var connectionInfo = _connectionStringFactory.LogDbConnection;

Loading…
Cancel
Save