Skip to content

Commit b29b799

Browse files
author
mwatson
committed
Updates for core
1 parent 26b53a6 commit b29b799

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+41475
-825
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
8+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
9+
<PropertyGroup Label="Globals">
10+
<ProjectGuid>2b832b34-ba30-4b5a-8e78-d6dc78af16fb</ProjectGuid>
11+
<RootNamespace>CoreConsoleApp</RootNamespace>
12+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
13+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
14+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
15+
</PropertyGroup>
16+
17+
<PropertyGroup>
18+
<SchemaVersion>2.0</SchemaVersion>
19+
</PropertyGroup>
20+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
21+
</Project>

Src/CoreConsoleApp/NLog.config

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
5+
>
6+
<extensions>
7+
<add assembly="NLog.Targets.Stackify"/>
8+
</extensions>
9+
<targets>
10+
<target name="stackify" xsi:type="StackifyTarget" />
11+
<target name="logfile" xsi:type="File" fileName="nlogfile.txt" />
12+
<target name="console" xsi:type="Console" />
13+
14+
</targets>
15+
<rules>
16+
<logger name="*" writeTo="stackify" minlevel="Debug" />
17+
<logger name="*" minlevel="Debug" writeTo="logfile" />
18+
<logger name="*" minlevel="Info" writeTo="console" />
19+
</rules>
20+
</nlog>

Src/CoreConsoleApp/Program.cs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Reflection;
7+
using System.Threading.Tasks;
8+
using System.Xml;
9+
using log4net.Config;
10+
using log4net.Repository;
11+
using Microsoft.Extensions.Configuration;
12+
using NLog;
13+
using NLog.Config;
14+
using StackifyLib;
15+
16+
namespace CoreConsoleApp
17+
{
18+
public class Program
19+
{
20+
21+
22+
23+
static void Main(string[] args)
24+
{
25+
var builder = new ConfigurationBuilder()
26+
.SetBasePath(Directory.GetCurrentDirectory())
27+
.AddJsonFile("appsettings.json", optional: true,
28+
reloadOnChange: true);
29+
30+
var config = builder.Build();
31+
config.ConfigureStackifyLogging();
32+
// OR
33+
//StackifyLib.Config.SetConfiguration(config);
34+
35+
//enable debug logging
36+
StackifyLib.Utils.StackifyAPILogger.OnLogMessage += StackifyAPILogger_OnLogMessage;
37+
StackifyLib.Utils.StackifyAPILogger.LogEnabled = true;
38+
39+
40+
NLogTest();
41+
42+
StackifyLib.Logger.Shutdown(); //best practice for console apps
43+
}
44+
45+
private static void NLogTest()
46+
{
47+
var path = Path.Combine(Directory.GetCurrentDirectory(), "nlog.config");
48+
49+
NLog.LogManager.Configuration = new XmlLoggingConfiguration(path, true);
50+
NLog.Logger nlog = LogManager.GetCurrentClassLogger();
51+
52+
for (int i = 0; i < 100; i++)
53+
{
54+
// StackifyLib.Logger.Queue("Debug", "Test message");
55+
//System.Threading.Thread.Sleep(1);
56+
nlog.Debug("Hello");
57+
//nlog.Debug(new { color = "red", int1 = 1 });
58+
}
59+
}
60+
61+
private static void Log4NetTest()
62+
{
63+
XmlDocument log4netConfig = new XmlDocument();
64+
65+
using (StreamReader reader = new StreamReader(new FileStream("log4net.config", FileMode.Open, FileAccess.Read)))
66+
{
67+
log4netConfig.Load(reader);
68+
}
69+
70+
ILoggerRepository rep = log4net.LogManager.CreateRepository(Assembly.GetEntryAssembly(), typeof(log4net.Repository.Hierarchy.Hierarchy));
71+
XmlConfigurator.Configure(rep, log4netConfig["log4net"]);
72+
73+
log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
74+
75+
for (int i = 0; i < 100; i++)
76+
{
77+
// StackifyLib.Logger.Queue("Debug", "Test message");
78+
//System.Threading.Thread.Sleep(1);
79+
log.Debug(new { color = "red", int1 = 1 });
80+
}
81+
82+
}
83+
84+
private static void StackifyAPILogger_OnLogMessage(string data)
85+
{
86+
Debug.WriteLine(data);
87+
}
88+
}
89+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyConfiguration("")]
9+
[assembly: AssemblyCompany("")]
10+
[assembly: AssemblyProduct("CoreConsoleApp")]
11+
[assembly: AssemblyTrademark("")]
12+
13+
// Setting ComVisible to false makes the types in this assembly not visible
14+
// to COM components. If you need to access a type in this assembly from
15+
// COM, set the ComVisible attribute to true on that type.
16+
[assembly: ComVisible(false)]
17+
18+
// The following GUID is for the ID of the typelib if this project is exposed to COM
19+
[assembly: Guid("2b832b34-ba30-4b5a-8e78-d6dc78af16fb")]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"Stackify": {
3+
"ApiKey": "",
4+
"AppName": "CoreConsoleApp",
5+
"Environment": "Dev"
6+
}
7+
}

Src/CoreConsoleApp/log4net.config

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<log4net>
2+
<root>
3+
<level value="DEBUG" />
4+
<appender-ref ref="LogFileAppender" />
5+
<appender-ref ref="ConsoleAppender" />
6+
<!--<appender-ref ref="StackifyAppender" />-->
7+
8+
</root>
9+
<!--<appender name="StackifyAppender" type="StackifyLib.log4net.StackifyAppender, StackifyLib.log4net" />-->
10+
11+
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
12+
<param name="File" value="prefix.log" />
13+
<param name="AppendToFile" value="true" />
14+
<rollingStyle value="Size" />
15+
<maxSizeRollBackups value="10" />
16+
<maximumFileSize value="10MB" />
17+
<staticLogFileName value="true" />
18+
<layout type="log4net.Layout.PatternLayout">
19+
<param name="ConversionPattern" value="%-5p %d{MM-dd hh:mm:ss.ffff} %m%n" />
20+
</layout>
21+
</appender>
22+
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
23+
<layout type="log4net.Layout.PatternLayout">
24+
<param name="Header" value="[Header]\r\n" />
25+
<param name="Footer" value="[Footer]\r\n" />
26+
<param name="ConversionPattern" value="%-5p %d{MM-dd hh:mm:ss.ffff}: %m%n" />
27+
</layout>
28+
</appender>
29+
</log4net>

Src/CoreConsoleApp/project.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"version": "1.0.0-*",
3+
"buildOptions": {
4+
"emitEntryPoint": true
5+
},
6+
7+
"dependencies": {
8+
"log4net": "2.0.7",
9+
"Microsoft.NETCore.App": "1.0.1",
10+
"NLog": "5.0.0-beta05",
11+
"Serilog": "2.4.0",
12+
"StackifyLib": "1.25.4",
13+
"NLog.Targets.Stackify": "1.25.4",
14+
"StackifyLib.log4net": "1.25.4",
15+
"Microsoft.Extensions.Configuration": "1.2.0-preview1-22736",
16+
"Microsoft.Extensions.Configuration.FileExtensions": "1.2.0-preview1-22736",
17+
"Microsoft.Extensions.Configuration.Json": "1.2.0-preview1-22736"
18+
},
19+
20+
"frameworks": {
21+
"netcoreapp1.0": {
22+
"imports": "dnxcore50"
23+
}
24+
25+
//"net452": {
26+
// "imports": "dnxcore50"
27+
//}
28+
},
29+
"runtimes": {
30+
"win10-x64" : {}
31+
}
32+
33+
34+
}

0 commit comments

Comments
 (0)