Skip to content

Commit 0b47cef

Browse files
committed
Adding sample
1 parent d5cdde1 commit 0b47cef

13 files changed

Lines changed: 395 additions & 39 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ node_modules
2929
project.lock.json
3030
.vs/
3131
*.dat
32+
Logs/

samples/LoggingReflectInsight/Console.ReflectInsightSample/Console.ReflectInsightSample.xproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
</PropertyGroup>
1414
<PropertyGroup>
1515
<SchemaVersion>2.0</SchemaVersion>
16+
<TypeScriptCompileBlocked>True</TypeScriptCompileBlocked>
1617
</PropertyGroup>
17-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
18-
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild>
19-
</PropertyGroup>
18+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'" />
19+
<ItemGroup>
20+
<Content Include="..\..\..\header\AspNet.Plus.licenseheader">
21+
<Link>AspNet.Plus.licenseheader</Link>
22+
</Content>
23+
</ItemGroup>
2024
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
2125
</Project>
Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,58 @@
1-
//using AspNet.Plus.Logging.ReflectInsight;
2-
using Microsoft.Extensions.Configuration;
1+
// ASP.NET.Plus
2+
// Copyright (c) 2016 ZoneMatrix Inc.
3+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
4+
5+
using AspNet.Plus.Logging.ReflectInsight;
36
using Microsoft.Extensions.Logging;
47
using System;
58
using System.Collections.Generic;
6-
using System.Linq;
7-
using System.Threading.Tasks;
89

910
namespace Console.ReflectInsightSample
1011
{
1112
public class Program
1213
{
1314
private static LoggerFactory _factory;
14-
private static IConfigurationRoot _loggingConfiguration;
1515

1616
public static void Main(string[] args)
17-
{
18-
_loggingConfiguration = new ConfigurationBuilder()
19-
//.AddXmlFile("ReflectInsight.config")
20-
.Build();
17+
{
18+
_factory = new LoggerFactory();
19+
_factory.MinimumLevel = LogLevel.Debug;
20+
_factory.AddReflectInsight();
21+
22+
var logger = _factory.CreateLogger<Program>();
23+
24+
var exception = new Exception("Some Exception...");
25+
var logValues = new Dictionary<string, object>();
26+
logValues["key1"] = "value1";
27+
logValues["key2"] = "value2";
28+
logValues["key3"] = new { Name = "John", Age = 100 };
29+
30+
logger.LogDebug("LogDebug");
31+
logger.LogDebug("LogDebug", exception);
32+
logger.LogDebug(logValues, exception);
33+
34+
logger.LogVerbose("LogVerbose");
35+
logger.LogVerbose("LogVerbose", exception);
36+
logger.LogVerbose(logValues, exception);
2137

22-
//_factory = new LoggerFactory();
23-
//_factory.AddReflectInsight();
38+
logger.LogInformation("LogInformation");
39+
logger.LogInformation("LogInformation", exception);
40+
logger.LogInformation(logValues, exception);
41+
42+
logger.LogWarning("LogWarning");
43+
logger.LogWarning("LogWarning", exception);
44+
logger.LogWarning(logValues, exception);
45+
46+
logger.LogError("LogError");
47+
logger.LogError("LogError", exception);
48+
logger.LogError(logValues, exception);
2449

25-
//var logger = _factory.CreateLogger<Program>();
50+
logger.LogCritical("LogCritical");
51+
logger.LogCritical("LogCritical", exception);
52+
logger.LogCritical(logValues, exception);
2653

27-
//logger.LogDebug("Debug");
28-
//logger.LogWarning("Warning");
54+
System.Console.WriteLine("Press any key to continue...");
55+
System.Console.ReadKey();
2956
}
3057
}
3158
}

samples/LoggingReflectInsight/Console.ReflectInsightSample/Properties/AssemblyInfo.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using System.Reflection;
1+
// ASP.NET.Plus
2+
// Copyright (c) 2016 ZoneMatrix Inc.
3+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
4+
5+
using System.Reflection;
26
using System.Runtime.CompilerServices;
37
using System.Runtime.InteropServices;
48

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"profiles": {}
3+
}

samples/LoggingReflectInsight/Console.ReflectInsightSample/ReflectInsight.config

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
<?xml version="1.0"?>
2+
<!--
3+
ASP.NET.Plus
4+
Copyright (c) 2016 ZoneMatrix Inc.
5+
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
6+
-->
27
<configuration>
38
<insightSettings>
49
<baseSettings>
510
<configChange enabled="true" />
611
<enable state="all" />
712
<propagateException enabled="false" />
813
<exceptionEventTracker time="5" />
9-
<senderName name="WebApi.ReflectInsightSample" />
14+
<senderName name="ReflectInsightSample" />
1015
</baseSettings>
1116

1217
<files default="Weekly">
@@ -36,15 +41,15 @@
3641
<group name="Development" enabled="true">
3742
<destinations>
3843
<destination name="Viewer" enabled="true" filter="Level_Trace" details="Viewer" />
39-
<destination name="BinaryFile" enabled="true" filter="Level_Trace" details="BinaryFile[path=$(workingdir)\Logs\Sample.rlg; autoSave=Weekly]" />
40-
<destination name="TextFile" enabled="true" filter="Level_Trace" details="TextFile[path=$(workingdir)\Logs\Sample.txt; messageDetails=Message; messagePattern=pattern1; autoSave=Weekly]" />
44+
<destination name="BinaryFile" enabled="true" filter="Level_Trace" details="BinaryFile[path=.\Logs\Sample.rlg; autoSave=Weekly]" />
45+
<destination name="TextFile" enabled="true" filter="Level_Trace" details="TextFile[path=.\Logs\Sample.txt; messageDetails=Message|Details; messagePattern=pattern1; autoSave=Weekly]" />
4146
</destinations>
4247
</group>
4348
<group name="Release" enabled="true">
4449
<destinations>
4550
<destination name="Viewer" enabled="true" filter="Level_Info" details="Viewer" />
46-
<destination name="BinaryFile" enabled="true" filter="Level_Info" details="BinaryFile[path=$(workingdir)\Logs\Sample.rlg; autoSave=Weekly]" />
47-
<destination name="TextFile" enabled="true" filter="Level_Info" details="TextFile[path=$(workingdir)\Logs\Sample.txt; messageDetails=Message; messagePattern=pattern1; autoSave=Weekly]" />
51+
<destination name="BinaryFile" enabled="true" filter="Level_Info" details="BinaryFile[path=.\Logs\Sample.rlg; autoSave=Weekly]" />
52+
<destination name="TextFile" enabled="true" filter="Level_Info" details="TextFile[path=.\LogsSample.txt; messageDetails=Message|Details; messagePattern=pattern1; autoSave=Weekly]" />
4853
</destinations>
4954
</group>
5055
</listenerGroups>
@@ -53,6 +58,8 @@
5358
<filter name="Level_Trace" mode="Include">
5459
<method type="SendTrace" />
5560
<method type="SendDebug" />
61+
<method type="SendVerbose" />
62+
<method type="SendSendMessage" />
5663
<method type="SendInformation" />
5764
<method type="SendWarning" />
5865
<method type="SendError" />
@@ -61,13 +68,16 @@
6168
</filter>
6269
<filter name="Level_Debug" mode="Include">
6370
<method type="SendDebug" />
71+
<method type="SendVerbose" />
72+
<method type="SendSendMessage" />
6473
<method type="SendInformation" />
6574
<method type="SendWarning" />
6675
<method type="SendError" />
6776
<method type="SendException" />
6877
<method type="SendFatal" />
6978
</filter>
7079
<filter name="Level_Info" mode="Include">
80+
<method type="SendSendMessage" />
7181
<method type="SendInformation" />
7282
<method type="SendWarning" />
7383
<method type="SendError" />
@@ -86,6 +96,7 @@
8696
<method type="SendFatal" />
8797
</filter>
8898
<filter name="Level_Critical" mode="Include">
99+
<method type="SendException" />
89100
<method type="SendFatal" />
90101
</filter>
91102
</filters>
@@ -94,12 +105,12 @@
94105
<publisher mode="on"
95106
name="EventPublisher"
96107
type="RI.Utils.ExceptionManagement.ExceptionEventPublisher, ReflectSoftware.Insight"
97-
applicationName="EndpointLoadAPI" />
108+
applicationName="ReflectInsightSample" />
98109

99110
<publisher mode="on"
100111
name="LogTextFilePublisher"
101112
type="RI.Utils.ExceptionManagement.ExceptionLogTextFilePublisher, ReflectSoftware.Insight"
102-
filePath="$(workingdir)\Logs\RI.Endpoints.Exceptions.txt"
113+
filePath=".\Logs\ReflectInsightSample.Exceptions.txt"
103114
recycle="7" />
104115
</exceptionManagement>
105116

samples/LoggingReflectInsight/Console.ReflectInsightSample/project.json

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,15 @@
22
"version": "1.0.0-*",
33

44
"dependencies": {
5-
"Microsoft.AspNet.FileProviders.Physical": "1.0.0-rc1-final",
6-
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc1-final",
7-
"Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
8-
"Microsoft.Extensions.Configuration.Xml": "1.0.0-rc1-final",
9-
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
10-
"Microsoft.Extensions.Logging": "1.0.0-rc1-final"
5+
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
6+
"AspNet.Plus.Logging.ReflectInsight": "1.0.0-*"
117
},
128

139
"commands": {
1410
"Console.ReflectInsightSample": "Console.ReflectInsightSample"
1511
},
1612

1713
"frameworks": {
18-
"dnx451": {
19-
"dependencies": {
20-
}
14+
"dnx451": { }
2115
}
22-
}
2316
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// ASP.NET.Plus
2+
// Copyright (c) 2016 ZoneMatrix Inc.
3+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
4+
5+
using Microsoft.Extensions.Logging;
6+
using System.Collections.Generic;
7+
8+
namespace AspNet.Plus.Logging.ReflectInsight
9+
{
10+
public class ReflectInsightLogValues : ILogValues
11+
{
12+
private static string _className;
13+
14+
private readonly IEnumerable<KeyValuePair<string, object>> _values;
15+
private readonly string _message;
16+
17+
/// <summary>
18+
/// Initializes the <see cref="ReflectInsightLogValues"/> class.
19+
/// </summary>
20+
static ReflectInsightLogValues()
21+
{
22+
_className = typeof(ReflectInsightLogValues).FullName;
23+
}
24+
25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="MyLogValues" /> class.
27+
/// </summary>
28+
/// <param name="values">The values.</param>
29+
/// <param name="message">The message.</param>
30+
public ReflectInsightLogValues(IEnumerable<KeyValuePair<string, object>> values, string message = null)
31+
{
32+
_values = values;
33+
_message = message ?? _className;
34+
}
35+
36+
/// <summary>
37+
/// Returns an enumerable of key value pairs mapping the name of the structured data to the data.
38+
/// </summary>
39+
/// <returns></returns>
40+
public IEnumerable<KeyValuePair<string, object>> GetValues()
41+
{
42+
return _values;
43+
}
44+
45+
/// <summary>
46+
/// Returns a <see cref="System.String" /> that represents this instance.
47+
/// </summary>
48+
/// <returns>
49+
/// A <see cref="System.String" /> that represents this instance.
50+
/// </returns>
51+
public override string ToString()
52+
{
53+
return _message;
54+
}
55+
}
56+
}

src/AspNet.Plus.Logging.ReflectInsight/ReflectInsightLogger.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using ReflectSoftware.Insight.Common;
88
using RI.Utils.ExceptionManagement;
99
using System;
10+
using System.Collections.Specialized;
1011

1112
namespace AspNet.Plus.Logging.ReflectInsight
1213
{
@@ -69,7 +70,7 @@ public bool IsEnabled(LogLevel logLevel)
6970
/// <exception cref="System.ArgumentNullException"></exception>
7071
public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func<object, Exception, string> formatter)
7172
{
72-
if (!IsEnabled(logLevel) || logLevel == LogLevel.None)
73+
if (!IsEnabled(logLevel)) // || logLevel == LogLevel.None)
7374
{
7475
return;
7576
}
@@ -117,7 +118,28 @@ public void Log(LogLevel logLevel, int eventId, object state, Exception exceptio
117118
var details = (string)null;
118119
if (exception != null)
119120
{
120-
details = ExceptionBasePublisher.ConstructIndentedMessage(exception);
121+
NameValueCollection additional = null;
122+
if(eventId > 0)
123+
{
124+
additional = new NameValueCollection();
125+
additional["eventId"] = eventId.ToString();
126+
}
127+
128+
if (state is ILogValues)
129+
{
130+
additional = additional ?? new NameValueCollection();
131+
132+
var logValues = (state as ILogValues);
133+
foreach(var keyValue in logValues.GetValues())
134+
{
135+
if (keyValue.Key != "{OriginalFormat}")
136+
{
137+
additional[keyValue.Key] = keyValue.Value?.ToString();
138+
}
139+
}
140+
}
141+
142+
details = ExceptionBasePublisher.ConstructIndentedMessage(exception, additional);
121143
}
122144

123145
RILogManager.Get(_name).Send(methodType, message, details);

0 commit comments

Comments
 (0)