Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions Backend/Converter/ChainsawToLogConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@ public IEnumerable<Log> Convert(string text) {
}
attribute = attributes.GetNamedItem("timestamp");
if (attribute != null) {
var timespan = TimeSpan.FromMilliseconds(Int64.Parse(attribute.Value));
log.Timestamp = new DateTime(1970, 1, 1).Add(timespan);
if (long.TryParse(attribute.Value, out var timestamp)) {
// log4j
log.Timestamp = DateTimeOffset.FromUnixTimeMilliseconds(timestamp).LocalDateTime;
} else {
// log4net
log.Timestamp = XmlConvert.ToDateTimeOffset(attribute.Value).LocalDateTime;
}
}
attribute = attributes.GetNamedItem("thread");
if (attribute != null) {
Expand All @@ -82,7 +87,7 @@ public IEnumerable<Log> Convert(string text) {
{
log.Message = $"{child.InnerText} {log.Message}";
}
if (child.Name.EndsWith("throwable")) {
if (child.Name.EndsWith("throwable") || child.Name.EndsWith("exception")) {
log.Exception = child.InnerText;
}
if (child.Name.EndsWith("properties")) {
Expand All @@ -95,9 +100,11 @@ public IEnumerable<Log> Convert(string text) {
var application = log.Properties.FirstOrDefault(m => m.Name == "log4japp");
log.Application = application == null ? Constants.APPLICATION_GLOBAL : application.Value;

log.MachineName = log.Properties.FirstOrDefault(m => m.Name == "log4jmachinename")?.Value;
var log4JMachineName = log.Properties.FirstOrDefault(m => m.Name == "log4jmachinename")?.Value;
var log4NetMachineName = log.Properties.FirstOrDefault(m => m.Name == "log4net:HostName")?.Value;
log.MachineName = log4JMachineName ?? log4NetMachineName;

var context = log.Properties.Where(m => !m.Name.StartsWith("log4j")).OrderBy(m => m.Name).Select(m => m.Name + ": " + m.Value);
var context = log.Properties.Where(m => !m.Name.StartsWith("log4j") && !m.Name.StartsWith("log4net")).OrderBy(m => m.Name).Select(m => m.Name + ": " + m.Value);
log.Context = String.Join(", ", context);
}
}
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ If the **timestamps are incorrect** (i.e. off by x hours): Remove existing confi

* Add option to group by application (name only)
* Export function
* Test with log4j and log4net
* Documentation for installation
* Other data sources (database, file, etc.) via polling

Expand Down