-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from stackify/CoreUpdates
Core updates
- Loading branch information
Showing
73 changed files
with
2,405 additions
and
10,085 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp1.0</TargetFramework> | ||
<AssemblyName>CoreConsoleApp</AssemblyName> | ||
<OutputType>Exe</OutputType> | ||
<PackageId>CoreConsoleApp</PackageId> | ||
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers> | ||
<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion> | ||
<PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback> | ||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> | ||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> | ||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\StackifyLib\StackifyLib.csproj" /> | ||
<ProjectReference Include="..\NLog.Targets.Stackify\NLog.Targets.Stackify.csproj" /> | ||
<ProjectReference Include="..\StackifyLib.log4net\StackifyLib.log4net.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="log4net" Version="2.0.7" /> | ||
<PackageReference Include="NLog" Version="5.0.0-beta05" /> | ||
<PackageReference Include="Serilog" Version="2.4.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="1.2.0-preview1-22736" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.2.0-preview1-22736" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.2.0-preview1-22736" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
|
||
> | ||
<extensions> | ||
<add assembly="NLog.Targets.Stackify"/> | ||
</extensions> | ||
<targets> | ||
<target name="stackify" xsi:type="StackifyTarget" /> | ||
<target name="logfile" xsi:type="File" fileName="nlogfile.txt" /> | ||
<target name="console" xsi:type="Console" /> | ||
|
||
</targets> | ||
<rules> | ||
<logger name="*" writeTo="stackify" minlevel="Debug" /> | ||
<logger name="*" minlevel="Debug" writeTo="logfile" /> | ||
<logger name="*" minlevel="Info" writeTo="console" /> | ||
</rules> | ||
</nlog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using System.Xml; | ||
using log4net.Config; | ||
using log4net.Repository; | ||
using Microsoft.Extensions.Configuration; | ||
using NLog; | ||
using NLog.Config; | ||
using StackifyLib; | ||
|
||
namespace CoreConsoleApp | ||
{ | ||
public class Program | ||
{ | ||
|
||
|
||
|
||
static void Main(string[] args) | ||
{ | ||
var builder = new ConfigurationBuilder() | ||
.SetBasePath(Directory.GetCurrentDirectory()) | ||
.AddJsonFile("appsettings.json", optional: true, | ||
reloadOnChange: true); | ||
|
||
var config = builder.Build(); | ||
config.ConfigureStackifyLogging(); | ||
// OR | ||
//StackifyLib.Config.SetConfiguration(config); | ||
|
||
//enable debug logging | ||
StackifyLib.Utils.StackifyAPILogger.OnLogMessage += StackifyAPILogger_OnLogMessage; | ||
StackifyLib.Utils.StackifyAPILogger.LogEnabled = true; | ||
|
||
|
||
NLogTest(); | ||
|
||
StackifyLib.Logger.Shutdown(); //best practice for console apps | ||
} | ||
|
||
private static void NLogTest() | ||
{ | ||
var path = Path.Combine(Directory.GetCurrentDirectory(), "nlog.config"); | ||
|
||
NLog.LogManager.Configuration = new XmlLoggingConfiguration(path, true); | ||
NLog.Logger nlog = LogManager.GetCurrentClassLogger(); | ||
|
||
for (int i = 0; i < 100; i++) | ||
{ | ||
// StackifyLib.Logger.Queue("Debug", "Test message"); | ||
//System.Threading.Thread.Sleep(1); | ||
nlog.Debug("Hello"); | ||
//nlog.Debug(new { color = "red", int1 = 1 }); | ||
} | ||
} | ||
|
||
private static void Log4NetTest() | ||
{ | ||
XmlDocument log4netConfig = new XmlDocument(); | ||
|
||
using (StreamReader reader = new StreamReader(new FileStream("log4net.config", FileMode.Open, FileAccess.Read))) | ||
{ | ||
log4netConfig.Load(reader); | ||
} | ||
|
||
ILoggerRepository rep = log4net.LogManager.CreateRepository(Assembly.GetEntryAssembly(), typeof(log4net.Repository.Hierarchy.Hierarchy)); | ||
XmlConfigurator.Configure(rep, log4netConfig["log4net"]); | ||
|
||
log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program)); | ||
|
||
for (int i = 0; i < 100; i++) | ||
{ | ||
// StackifyLib.Logger.Queue("Debug", "Test message"); | ||
//System.Threading.Thread.Sleep(1); | ||
log.Debug(new { color = "red", int1 = 1 }); | ||
} | ||
|
||
} | ||
|
||
private static void StackifyAPILogger_OnLogMessage(string data) | ||
{ | ||
Debug.WriteLine(data); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("CoreConsoleApp")] | ||
[assembly: AssemblyTrademark("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("2b832b34-ba30-4b5a-8e78-d6dc78af16fb")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"Stackify": { | ||
"ApiKey": "", | ||
"AppName": "CoreConsoleApp", | ||
"Environment": "Dev" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<log4net> | ||
<root> | ||
<level value="DEBUG" /> | ||
<appender-ref ref="LogFileAppender" /> | ||
<appender-ref ref="ConsoleAppender" /> | ||
<!--<appender-ref ref="StackifyAppender" />--> | ||
|
||
</root> | ||
<!--<appender name="StackifyAppender" type="StackifyLib.log4net.StackifyAppender, StackifyLib.log4net" />--> | ||
|
||
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender"> | ||
<param name="File" value="prefix.log" /> | ||
<param name="AppendToFile" value="true" /> | ||
<rollingStyle value="Size" /> | ||
<maxSizeRollBackups value="10" /> | ||
<maximumFileSize value="10MB" /> | ||
<staticLogFileName value="true" /> | ||
<layout type="log4net.Layout.PatternLayout"> | ||
<param name="ConversionPattern" value="%-5p %d{MM-dd hh:mm:ss.ffff} %m%n" /> | ||
</layout> | ||
</appender> | ||
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender"> | ||
<layout type="log4net.Layout.PatternLayout"> | ||
<param name="Header" value="[Header]\r\n" /> | ||
<param name="Footer" value="[Footer]\r\n" /> | ||
<param name="ConversionPattern" value="%-5p %d{MM-dd hh:mm:ss.ffff}: %m%n" /> | ||
</layout> | ||
</appender> | ||
</log4net> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using StackifyLib.CoreLogger; | ||
|
||
namespace CoreWebApp | ||
{ | ||
public class ApplicationLogging | ||
{ | ||
private static ILoggerFactory _Factory = null; | ||
|
||
public static void ConfigureLogger(ILoggerFactory factory) | ||
{ | ||
factory.AddDebug(LogLevel.None).AddStackify(); | ||
factory.AddFile("logFileFromHelper.log"); //serilog file extension | ||
} | ||
|
||
public static ILoggerFactory LoggerFactory | ||
{ | ||
get | ||
{ | ||
if (_Factory == null) | ||
{ | ||
_Factory = new LoggerFactory(); | ||
ConfigureLogger(_Factory); | ||
} | ||
return _Factory; | ||
} | ||
set { _Factory = value; } | ||
} | ||
public static ILogger<T> CreateLogger<T>() => LoggerFactory.CreateLogger<T>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace CoreWebApp.Controllers | ||
{ | ||
public class SomeOtherClass | ||
{ | ||
public SomeOtherClass() | ||
{ | ||
} | ||
|
||
public async Task<string> DoBadWebRequest() | ||
{ | ||
try | ||
{ | ||
using (HttpClient hc = new HttpClient()) | ||
{ | ||
var data = await hc.GetStringAsync("https://stackify.comm"); | ||
return data; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
var logger = ApplicationLogging.CreateLogger<SomeOtherClass>(); | ||
logger.LogError("Error! " + ex.ToString()); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using NLog; | ||
|
||
namespace CoreWebApp.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
public class ValuesController : Controller | ||
{ | ||
static NLog.Logger nlog = LogManager.GetCurrentClassLogger(); | ||
|
||
private static ILogger<ValuesController> _Logger = ApplicationLogging.CreateLogger<ValuesController>(); | ||
|
||
[HttpGet] | ||
public IEnumerable<string> Get() | ||
{ | ||
// nlog.Debug("Callng Get() method"); | ||
|
||
_Logger.LogError("From helper method"); | ||
|
||
try | ||
{ | ||
throw new InvalidOperationException("Bring the boom"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
nlog.Error(ex, "Uh oh"); | ||
} | ||
|
||
SomeOtherClass soc = new SomeOtherClass(); | ||
soc.DoBadWebRequest(); | ||
|
||
return new string[] { "value1", "value2" }; | ||
} | ||
|
||
// GET api/values/5 | ||
[HttpGet("{id}")] | ||
public string Get(int id) | ||
{ | ||
return "value"; | ||
} | ||
|
||
// POST api/values | ||
[HttpPost] | ||
public void Post([FromBody]string value) | ||
{ | ||
} | ||
|
||
// PUT api/values/5 | ||
[HttpPut("{id}")] | ||
public void Put(int id, [FromBody]string value) | ||
{ | ||
} | ||
|
||
// DELETE api/values/5 | ||
[HttpDelete("{id}")] | ||
public void Delete(int id) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp1.0</TargetFramework> | ||
<PreserveCompilationContext>true</PreserveCompilationContext> | ||
<AssemblyName>CoreWebApp</AssemblyName> | ||
<OutputType>Exe</OutputType> | ||
<PackageId>CoreWebApp</PackageId> | ||
<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion> | ||
<PackageTargetFallback>$(PackageTargetFallback);dotnet5.6;portable-net45+win8</PackageTargetFallback> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Update="wwwroot\**\*"> | ||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\StackifyLib\StackifyLib.csproj" /> | ||
<ProjectReference Include="..\StackifyLib.CoreLogger\StackifyLib.CoreLogger.csproj" /> | ||
<ProjectReference Include="..\NLog.Targets.Stackify\NLog.Targets.Stackify.csproj" /> | ||
<ProjectReference Include="..\StackifyLib.log4net\StackifyLib.log4net.csproj" /> | ||
<ProjectReference Include="..\StackifyLib.AspNetCore\StackifyLib.AspNetCore.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.3" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="1.0.3" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.0.2" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.0.3" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.0.2" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.0.2" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.0.2" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.0.2" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.0.2" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.0.2" /> | ||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.0.2" /> | ||
<PackageReference Include="NLog" Version="5.0.0-beta05" /> | ||
<PackageReference Include="NLog.Extensions.Logging" Version="1.0.0-rtm-beta2" /> | ||
<PackageReference Include="Serilog" Version="2.4.0" /> | ||
<PackageReference Include="Serilog.Extensions.Logging" Version="1.4.0" /> | ||
<PackageReference Include="Serilog.Extensions.Logging.File" Version="1.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.