Skip to content

Commit

Permalink
Adding NLog samples
Browse files Browse the repository at this point in the history
  • Loading branch information
ferventcoder committed Dec 20, 2012
1 parent fe69bf4 commit e878a76
Show file tree
Hide file tree
Showing 24 changed files with 559 additions and 23 deletions.
37 changes: 37 additions & 0 deletions LoggingExtensions.NLog.Sample/App.config
@@ -0,0 +1,37 @@
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<nlog>
<targets>
<target name="console" type="Console"
layout="${message}"
/>
<target name="file" type="AsyncWrapper"
queueLimit="5000"
overflowAction="Discard">
<target type="File"
fileName="${basedir}/logs/this.Log-NLog.Sample.log"
layout="${longdate} ${threadid} [${level:uppercase=true}] ${message}"
/>
</target>
<target name="errorSmtp" type="Mail"
layout="${longdate} ${threadid} [${level:uppercase=true}] ${logger} - ${message}"
subject="this.Log Sample Console Errors - LOCAL DEBUG"
to="noone@noreply.org"
from="this.Log.sample@noreply.org"
smtpServer="localhost"
/>
</targets>

<rules>
<logger name="*" minlevel="Debug" writeTo="file" />
<logger name="*" minlevel="Debug" writeTo="console" />
<logger name="*" minlevel="Error" writeTo="errorSmtp" />
</rules>
</nlog>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
56 changes: 56 additions & 0 deletions LoggingExtensions.NLog.Sample/LogExtensions.cs
@@ -0,0 +1,56 @@
// ==============================================================================
//
// RealDimensions Software, LLC - Copyright © 2012 - Present - Released under the Apache 2.0 License
//
// Copyright 2007-2008 The Apache Software Foundation.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
// ==============================================================================

namespace LoggingExtensions.Sample.NLog
{
using System.Collections.Concurrent;
using LoggingExtensions.Logging;

/// <summary>
/// Extensions to help make logging awesome - this should be installed into the root namespace of your application
/// </summary>
public static class LogExtensions
{
/// <summary>
/// Concurrent dictionary that ensures only one instance of a logger for a type.
/// </summary>
private static readonly ConcurrentDictionary<string, ILog> _dictionary = new ConcurrentDictionary<string, ILog>();

/// <summary>
/// Gets the logger for <see cref="T"/>.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="type">The type to get the logger for.</param>
/// <returns>Instance of a logger for the object.</returns>
public static ILog Log<T>(this T type)
{
string objectName = typeof (T).FullName;
return Log(objectName);
}

/// <summary>
/// Gets the logger for the specified object name.
/// </summary>
/// <param name="objectName">Either use the fully qualified object name or the short. If used with Log&lt;T&gt;() you must use the fully qualified object name"/></param>
/// <returns>Instance of a logger for the object.</returns>
public static ILog Log(this string objectName)
{
return _dictionary.GetOrAdd(objectName, LoggingExtensions.Logging.Log.GetLoggerFor);
}
}
}
13 changes: 13 additions & 0 deletions LoggingExtensions.NLog.Sample/Properties/AssemblyInfo.cs
@@ -0,0 +1,13 @@
using System.Reflection;
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: AssemblyTitle("this.Log-log4net.Sample")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyProduct("this.Log-log4net.Sample")]

// The following GUID is for the ID of the typelib if this project is exposed to COM

[assembly: Guid("81591123-786f-44c8-b3fa-2dc3ed0155ee")]
34 changes: 34 additions & 0 deletions LoggingExtensions.NLog.Sample/SampleRun.cs
@@ -0,0 +1,34 @@
// ==============================================================================
//
// RealDimensions Software, LLC - Copyright © 2012 - Present - Released under the Apache 2.0 License
//
// Copyright 2007-2008 The Apache Software Foundation.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
// ==============================================================================

namespace LoggingExtensions.Sample.NLog
{

/// <summary>
/// Make sure this is added to a console x86 project (not Client Profile). Set the startup object to SampleRun. Take a look at the logging folder afterwards.
/// </summary>
public class SampleRun
{
private static void Main(string[] args)
{
LoggingExtensions.Logging.Log.InitializeWith<LoggingExtensions.NLog.NLogLog>();

"Main".Log().Info(() => "This is a logging message");
}
}
}
34 changes: 34 additions & 0 deletions LoggingExtensions.NLog.Sample/SampleRun.cs.pp
@@ -0,0 +1,34 @@
// ==============================================================================
//
// RealDimensions Software, LLC - Copyright © 2012 - Present - Released under the Apache 2.0 License
//
// Copyright 2007-2008 The Apache Software Foundation.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
// ==============================================================================

namespace $rootnamespace$
{

/// <summary>
/// Make sure this is added to a console x86 project (not Client Profile). Set the startup object to SampleRun. Take a look at the logging folder afterwards.
/// </summary>
public class SampleRun
{
private static void Main(string[] args)
{
LoggingExtensions.Logging.Log.InitializeWith<LoggingExtensions.NLog.NLogLog>();

"Main".Log().Info(() => "This is a logging message");
}
}
}
34 changes: 34 additions & 0 deletions LoggingExtensions.NLog.Sample/app.config.transform
@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<nlog>
<targets>
<target name="console" type="Console"
layout="${message}"
/>
<target name="file" type="AsyncWrapper"
queueLimit="5000"
overflowAction="Discard">
<target type="File"
fileName="${basedir}/logs/this.Log-NLog.Sample.log"
layout="${longdate} ${threadid} [${level:uppercase=true}] ${message}"
/>
</target>
<target name="errorSmtp" type="Mail"
layout="${longdate} ${threadid} [${level:uppercase=true}] ${logger} - ${message}"
subject="this.Log Sample Console Errors - LOCAL DEBUG"
to="noone@noreply.org"
from="this.Log.sample@noreply.org"
smtpServer="localhost"
/>
</targets>

<rules>
<logger name="*" minlevel="Debug" writeTo="file" />
<logger name="*" minlevel="Debug" writeTo="console" />
<logger name="*" minlevel="Error" writeTo="errorSmtp" />
</rules>
</nlog>
</configuration>
6 changes: 6 additions & 0 deletions LoggingExtensions.NLog.Sample/packages.config
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NLog" version="2.0.0.2000" targetFramework="net40" />
<package id="this.Log" version="0.0.1.0" targetFramework="net40-Client" />
<package id="this.Log-NLog" version="0.0.1.0" targetFramework="net40-Client" />
</packages>
27 changes: 27 additions & 0 deletions LoggingExtensions.NLog.Sample/this.Log-NLog.Sample.nuspec
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<package>
<metadata>
<id>this.Log-NLog.Sample</id>
<version>0.0.1.0</version>
<title>this.Log Logging Extension (NLog Plugin) SAMPLE</title>
<authors>RealDimensions Software, LLC</authors>
<owners>Rob Reynolds</owners>
<projectUrl>https://github.com/ferventcoder/this.Log</projectUrl>
<licenseUrl>https://raw.github.com/ferventcoder/this.Log/master/LICENSE</licenseUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<summary>this.Log-NLog.Sample - this.Log logging extension using NLog</summary>
<description>this.Log-NLog.Sample is a sample of how to use the NLog plugin to this.Log logging extension.</description>
<releaseNotes>
</releaseNotes>
<copyright>Copyright 2012</copyright>
<tags>logging log this.Log NLog sample</tags>
<dependencies>
<dependency id="this.Log-NLog" version="0.0.1.0" />
</dependencies>
</metadata>
<files>
<file src="SampleRun.cs.pp" target="content" />
<file src="app.config.transform" target="content" />
<file src="web.config.transform" target="content" />
</files>
</package>
34 changes: 34 additions & 0 deletions LoggingExtensions.NLog.Sample/web.config.transform
@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<nlog>
<targets>
<target name="console" type="Console"
layout="${message}"
/>
<target name="file" type="AsyncWrapper"
queueLimit="5000"
overflowAction="Discard">
<target type="File"
fileName="${basedir}/logs/this.Log-NLog.Sample.log"
layout="${longdate} ${threadid} [${level:uppercase=true}] ${message}"
/>
</target>
<target name="errorSmtp" type="Mail"
layout="${longdate} ${threadid} [${level:uppercase=true}] ${logger} - ${message}"
subject="this.Log Sample Console Errors - LOCAL DEBUG"
to="noone@noreply.org"
from="this.Log.sample@noreply.org"
smtpServer="localhost"
/>
</targets>

<rules>
<logger name="*" minlevel="Debug" writeTo="file" />
<logger name="*" minlevel="Debug" writeTo="console" />
<logger name="*" minlevel="Error" writeTo="errorSmtp" />
</rules>
</nlog>
</configuration>
56 changes: 56 additions & 0 deletions LoggingExtensions.NLog.VB.Sample/LogExtensions.vb
@@ -0,0 +1,56 @@
' ==============================================================================
'
' RealDimensions Software, LLC - Copyright © 2012 - Present - Released under the Apache 2.0 License
'
' Copyright 2007-2008 The Apache Software Foundation.
'
' Licensed under the Apache License, Version 2.0 (the "License"); you may not use
' this file except in compliance with the License. You may obtain a copy of the
' License at
'
' http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software distributed
' under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
' CONDITIONS OF ANY KIND, either express or implied. See the License for the
' specific language governing permissions and limitations under the License.
' ==============================================================================

Imports System.Collections.Concurrent
Imports System.Runtime.CompilerServices
Imports LoggingExtensions.Logging

''' <summary>
''' Extensions to help make logging awesome - this should be installed into the root namespace of your application
''' </summary>
Public Module LogExtensions

''' <summary>
''' Concurrent dictionary that ensures only one instance of a logger for a type.
''' </summary>
Private ReadOnly _dictionary As ConcurrentDictionary(Of String, ILog) = New ConcurrentDictionary(Of String, ILog)

''' <summary>
''' Gets the logger for the type indicated.
''' </summary>
''' <typeparam name="T"></typeparam>
''' <param name="type">The type to get the logger for.</param>
''' <returns>Instance of a logger for the object.</returns>
<Extension()>
Public Function Log(Of T)(type As T) As ILog
Dim objectName As String = GetType(T).FullName

Return Log(objectName)
End Function

''' <summary>
''' Gets the logger for the specified object name.
''' </summary>
''' <param name="objectName">Either use the fully qualified object name or the short. If used with Log(Of T)() you must use the fully qualified object name"/></param>
''' <returns>Instance of a logger for the object.</returns>
<Extension()>
Public Function Log(objectName As String) As ILog
Return _dictionary.GetOrAdd(objectName, Function(name) (LoggingExtensions.Logging.Log.GetLoggerFor(name)))
End Function

End Module
15 changes: 15 additions & 0 deletions LoggingExtensions.NLog.VB.Sample/My Project/AssemblyInfo.vb
@@ -0,0 +1,15 @@
Imports System.Reflection
Imports 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.

' Review the values of the assembly attributes

<Assembly: AssemblyTitle("this.Log-log4net.Sample.VB")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyProduct("this.Log-log4net.Sample.VB")>

'The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid("e779a01c-5479-4156-8d66-a146a9566366")>
13 changes: 13 additions & 0 deletions LoggingExtensions.NLog.VB.Sample/SampleRun.vb
@@ -0,0 +1,13 @@
Public Module SampleRun

''' <summary>
''' The main entry point for the application.
''' </summary>
Public Sub Main(ByVal args() As String)
LoggingExtensions.Logging.Log.InitializeWith(Of LoggingExtensions.NLog.NLogLog)()

Dim test As New TestClass()
test.Noop()
End Sub

End Module
13 changes: 13 additions & 0 deletions LoggingExtensions.NLog.VB.Sample/SampleRun.vb.pp
@@ -0,0 +1,13 @@
Public Module SampleRun

''' <summary>
''' The main entry point for the application.
''' </summary>
Public Sub Main(ByVal args() As String)
LoggingExtensions.Logging.Log.InitializeWith(Of LoggingExtensions.NLog.NLogLog)()
Dim test As New TestClass()
test.Noop()
End Sub
End Module

0 comments on commit e878a76

Please sign in to comment.