Skip to content

Commit 88e673c

Browse files
authored
Merge pull request #41 from stackify/CoreUpdates
Core updates
2 parents 607dcd5 + 29db3a3 commit 88e673c

File tree

73 files changed

+2405
-10085
lines changed

Some content is hidden

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

73 files changed

+2405
-10085
lines changed
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp1.0</TargetFramework>
5+
<AssemblyName>CoreConsoleApp</AssemblyName>
6+
<OutputType>Exe</OutputType>
7+
<PackageId>CoreConsoleApp</PackageId>
8+
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
9+
<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion>
10+
<PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
11+
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
12+
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
13+
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
14+
</PropertyGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\StackifyLib\StackifyLib.csproj" />
18+
<ProjectReference Include="..\NLog.Targets.Stackify\NLog.Targets.Stackify.csproj" />
19+
<ProjectReference Include="..\StackifyLib.log4net\StackifyLib.log4net.csproj" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<PackageReference Include="log4net" Version="2.0.7" />
24+
<PackageReference Include="NLog" Version="5.0.0-beta05" />
25+
<PackageReference Include="Serilog" Version="2.4.0" />
26+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="1.2.0-preview1-22736" />
27+
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.2.0-preview1-22736" />
28+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.2.0-preview1-22736" />
29+
</ItemGroup>
30+
31+
</Project>

Src/CoreConsoleApp/NLog.config

+20
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

+89
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+
}
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")]

Src/CoreConsoleApp/appsettings.json

+7
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

+29
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/CoreWebApp/ApplicationLogging.cs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.Extensions.Logging;
6+
using StackifyLib.CoreLogger;
7+
8+
namespace CoreWebApp
9+
{
10+
public class ApplicationLogging
11+
{
12+
private static ILoggerFactory _Factory = null;
13+
14+
public static void ConfigureLogger(ILoggerFactory factory)
15+
{
16+
factory.AddDebug(LogLevel.None).AddStackify();
17+
factory.AddFile("logFileFromHelper.log"); //serilog file extension
18+
}
19+
20+
public static ILoggerFactory LoggerFactory
21+
{
22+
get
23+
{
24+
if (_Factory == null)
25+
{
26+
_Factory = new LoggerFactory();
27+
ConfigureLogger(_Factory);
28+
}
29+
return _Factory;
30+
}
31+
set { _Factory = value; }
32+
}
33+
public static ILogger<T> CreateLogger<T>() => LoggerFactory.CreateLogger<T>();
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Net.Http;
5+
using System.Threading.Tasks;
6+
using Microsoft.Extensions.Logging;
7+
8+
namespace CoreWebApp.Controllers
9+
{
10+
public class SomeOtherClass
11+
{
12+
public SomeOtherClass()
13+
{
14+
}
15+
16+
public async Task<string> DoBadWebRequest()
17+
{
18+
try
19+
{
20+
using (HttpClient hc = new HttpClient())
21+
{
22+
var data = await hc.GetStringAsync("https://stackify.comm");
23+
return data;
24+
}
25+
}
26+
catch (Exception ex)
27+
{
28+
var logger = ApplicationLogging.CreateLogger<SomeOtherClass>();
29+
logger.LogError("Error! " + ex.ToString());
30+
}
31+
32+
return null;
33+
}
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using Microsoft.Extensions.Logging;
8+
using NLog;
9+
10+
namespace CoreWebApp.Controllers
11+
{
12+
[Route("api/[controller]")]
13+
public class ValuesController : Controller
14+
{
15+
static NLog.Logger nlog = LogManager.GetCurrentClassLogger();
16+
17+
private static ILogger<ValuesController> _Logger = ApplicationLogging.CreateLogger<ValuesController>();
18+
19+
[HttpGet]
20+
public IEnumerable<string> Get()
21+
{
22+
// nlog.Debug("Callng Get() method");
23+
24+
_Logger.LogError("From helper method");
25+
26+
try
27+
{
28+
throw new InvalidOperationException("Bring the boom");
29+
}
30+
catch (Exception ex)
31+
{
32+
nlog.Error(ex, "Uh oh");
33+
}
34+
35+
SomeOtherClass soc = new SomeOtherClass();
36+
soc.DoBadWebRequest();
37+
38+
return new string[] { "value1", "value2" };
39+
}
40+
41+
// GET api/values/5
42+
[HttpGet("{id}")]
43+
public string Get(int id)
44+
{
45+
return "value";
46+
}
47+
48+
// POST api/values
49+
[HttpPost]
50+
public void Post([FromBody]string value)
51+
{
52+
}
53+
54+
// PUT api/values/5
55+
[HttpPut("{id}")]
56+
public void Put(int id, [FromBody]string value)
57+
{
58+
}
59+
60+
// DELETE api/values/5
61+
[HttpDelete("{id}")]
62+
public void Delete(int id)
63+
{
64+
}
65+
}
66+
}

Src/CoreWebApp/CoreWebApp.csproj

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp1.0</TargetFramework>
5+
<PreserveCompilationContext>true</PreserveCompilationContext>
6+
<AssemblyName>CoreWebApp</AssemblyName>
7+
<OutputType>Exe</OutputType>
8+
<PackageId>CoreWebApp</PackageId>
9+
<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion>
10+
<PackageTargetFallback>$(PackageTargetFallback);dotnet5.6;portable-net45+win8</PackageTargetFallback>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<None Update="wwwroot\**\*">
15+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
16+
</None>
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<ProjectReference Include="..\StackifyLib\StackifyLib.csproj" />
21+
<ProjectReference Include="..\StackifyLib.CoreLogger\StackifyLib.CoreLogger.csproj" />
22+
<ProjectReference Include="..\NLog.Targets.Stackify\NLog.Targets.Stackify.csproj" />
23+
<ProjectReference Include="..\StackifyLib.log4net\StackifyLib.log4net.csproj" />
24+
<ProjectReference Include="..\StackifyLib.AspNetCore\StackifyLib.AspNetCore.csproj" />
25+
</ItemGroup>
26+
27+
<ItemGroup>
28+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.3" />
29+
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="1.0.3" />
30+
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.0.2" />
31+
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.0.3" />
32+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.0.2" />
33+
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.0.2" />
34+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.0.2" />
35+
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.0.2" />
36+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.0.2" />
37+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.0.2" />
38+
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.0.2" />
39+
<PackageReference Include="NLog" Version="5.0.0-beta05" />
40+
<PackageReference Include="NLog.Extensions.Logging" Version="1.0.0-rtm-beta2" />
41+
<PackageReference Include="Serilog" Version="2.4.0" />
42+
<PackageReference Include="Serilog.Extensions.Logging" Version="1.4.0" />
43+
<PackageReference Include="Serilog.Extensions.Logging.File" Version="1.0.0" />
44+
</ItemGroup>
45+
46+
</Project>

0 commit comments

Comments
 (0)