Skip to content

Commit

Permalink
Add dynamic columns per file properties. Fix #43
Browse files Browse the repository at this point in the history
  • Loading branch information
LiorBanai committed Jul 3, 2020
1 parent 839eead commit faa9a32
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Analogy.LogViewer.Serilog/Analogy.LogViewer.Serilog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
<PackageIcon>AnalogySerilog.png</PackageIcon>
<PackageIconUrl />
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.2.0</Version>
<AssemblyVersion>1.2.0.0</AssemblyVersion>
<Version>1.2.1</Version>
<AssemblyVersion>1.2.1.0</AssemblyVersion>
<Company>Analogy.LogViewer</Company>
<FileVersion>1.2.0.0</FileVersion>
<FileVersion>1.2.1.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions Analogy.LogViewer.Serilog/ChangeLogList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public static class ChangeLogList
{
public static IEnumerable<AnalogyChangeLog> GetChangeLog()
{
yield return new AnalogyChangeLog("Add dynamic columns per file properties. #43", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2020, 07, 03));
yield return new AnalogyChangeLog("Initial version", AnalogChangeLogType.None, "Lior Banai", new DateTime(2019, 12, 14));
}
}
Expand Down
22 changes: 21 additions & 1 deletion Analogy.LogViewer.Serilog/CommonParser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Analogy.Interfaces;
using System.Collections.Generic;
using Analogy.Interfaces;
using Analogy.LogViewer.Serilog.Managers;
using Serilog.Events;

Expand All @@ -10,6 +11,7 @@ public static class CommonParser
public static AnalogyLogMessage ParseLogEventProperties(LogEvent evt)
{
AnalogyLogMessage m = new AnalogyLogMessage();

switch (evt.Level)
{
case LogEventLevel.Verbose:
Expand Down Expand Up @@ -105,6 +107,24 @@ public static AnalogyLogMessage ParseLogEventProperties(LogEvent evt)
m.User = environmentUserNameString;
}
}
if (evt.Properties.TryGetValue(Constants.User, out var environmentUser))
{
if (environmentUser is ScalarValue scalarValue &&
scalarValue.Value is string environmentUserString)
{
m.User = environmentUserString;
}
if (environmentUser is StructureValue structure)

{
m.User = structure.ToString();
}
}
m.AdditionalInformation = new Dictionary<string, string>();
foreach (KeyValuePair<string, LogEventPropertyValue> property in evt.Properties)
{
m.AdditionalInformation.Add(property.Key, property.Value.ToString());
}
return m;
}
}
Expand Down
1 change: 1 addition & 0 deletions Analogy.LogViewer.Serilog/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public static class Constants
public static string ProcessId { get; } = "ProcessId";
public static string ProcessName { get; } = "ProcessName";
public static string MachineName { get; } = "MachineName";
public static string User { get; } = "User";
public static string EnvironmentUserName { get; } = "EnvironmentUserName";
}
}

0 comments on commit faa9a32

Please sign in to comment.