Skip to content
This repository has been archived by the owner on Jun 8, 2019. It is now read-only.

Variety of improvements #11

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ tools/SHFB export-ignore
tools/Sandcastle export-ignore
tools/Wix export-ignore


* text=auto

116 changes: 58 additions & 58 deletions src/NLog.monodevelop.sln
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NLog.monodevelop", "NLog\NLog.monodevelop.csproj", "{E7AB20BF-6920-442A-B876-CC05BC5CEC79}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NLog.Extended.monodevelop", "NLog.Extended\NLog.Extended.monodevelop.csproj", "{F801A1F9-1024-4446-BF9E-A923137340B8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleExtensions.monodevelop", "..\tests\SampleExtensions\SampleExtensions.monodevelop.csproj", "{C480452F-7E14-443D-906D-7E021ABAA107A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NLog.UnitTests.monodevelop", "..\tests\NLog.UnitTests\NLog.UnitTests.monodevelop.csproj", "{FE0A3713-E9A8-41F0-89FA-C1126F8FB6A8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Default|Any CPU = Default|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C480452F-7E14-443D-906D-7E021ABAA107A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C480452F-7E14-443D-906D-7E021ABAA107A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C480452F-7E14-443D-906D-7E021ABAA107A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C480452F-7E14-443D-906D-7E021ABAA107A}.Release|Any CPU.Build.0 = Release|Any CPU
{E7AB20BF-6920-442A-B876-CC05BC5CEC79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7AB20BF-6920-442A-B876-CC05BC5CEC79}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7AB20BF-6920-442A-B876-CC05BC5CEC79}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7AB20BF-6920-442A-B876-CC05BC5CEC79}.Release|Any CPU.Build.0 = Release|Any CPU
{F801A1F9-1024-4446-BF9E-A923137340B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F801A1F9-1024-4446-BF9E-A923137340B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F801A1F9-1024-4446-BF9E-A923137340B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F801A1F9-1024-4446-BF9E-A923137340B8}.Release|Any CPU.Build.0 = Release|Any CPU
{FE0A3713-E9A8-41F0-89FA-C1126F8FB6A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FE0A3713-E9A8-41F0-89FA-C1126F8FB6A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FE0A3713-E9A8-41F0-89FA-C1126F8FB6A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FE0A3713-E9A8-41F0-89FA-C1126F8FB6A8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = ..\tests\NLog.UnitTests\NLog.UnitTests.monodevelop.csproj
Policies = $0
$0.TextStylePolicy = $1
$1.inheritsSet = null
$1.scope = text/x-csharp
$0.CSharpFormattingPolicy = $2
$2.inheritsSet = Mono
$2.inheritsScope = text/x-csharp
$2.scope = text/x-csharp
$0.TextStylePolicy = $3
$3.inheritsSet = VisualStudio
$3.inheritsScope = text/plain
$3.scope = text/plain
$0.TextStylePolicy = $4
$4.inheritsSet = null
$4.scope = application/xml
$0.XmlFormattingPolicy = $5
$5.inheritsSet = Mono
$5.inheritsScope = application/xml
$5.scope = application/xml
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NLog.monodevelop", "NLog\NLog.monodevelop.csproj", "{E7AB20BF-6920-442A-B876-CC05BC5CEC79}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NLog.Extended.monodevelop", "NLog.Extended\NLog.Extended.monodevelop.csproj", "{F801A1F9-1024-4446-BF9E-A923137340B8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleExtensions.monodevelop", "..\tests\SampleExtensions\SampleExtensions.monodevelop.csproj", "{C480452F-7E14-443D-906D-7E021ABAA107A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NLog.UnitTests.monodevelop", "..\tests\NLog.UnitTests\NLog.UnitTests.monodevelop.csproj", "{FE0A3713-E9A8-41F0-89FA-C1126F8FB6A8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Default|Any CPU = Default|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C480452F-7E14-443D-906D-7E021ABAA107A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C480452F-7E14-443D-906D-7E021ABAA107A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C480452F-7E14-443D-906D-7E021ABAA107A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C480452F-7E14-443D-906D-7E021ABAA107A}.Release|Any CPU.Build.0 = Release|Any CPU
{E7AB20BF-6920-442A-B876-CC05BC5CEC79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7AB20BF-6920-442A-B876-CC05BC5CEC79}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7AB20BF-6920-442A-B876-CC05BC5CEC79}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7AB20BF-6920-442A-B876-CC05BC5CEC79}.Release|Any CPU.Build.0 = Release|Any CPU
{F801A1F9-1024-4446-BF9E-A923137340B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F801A1F9-1024-4446-BF9E-A923137340B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F801A1F9-1024-4446-BF9E-A923137340B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F801A1F9-1024-4446-BF9E-A923137340B8}.Release|Any CPU.Build.0 = Release|Any CPU
{FE0A3713-E9A8-41F0-89FA-C1126F8FB6A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FE0A3713-E9A8-41F0-89FA-C1126F8FB6A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FE0A3713-E9A8-41F0-89FA-C1126F8FB6A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FE0A3713-E9A8-41F0-89FA-C1126F8FB6A8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = ..\tests\NLog.UnitTests\NLog.UnitTests.monodevelop.csproj
Policies = $0
$0.TextStylePolicy = $1
$1.inheritsSet = null
$1.scope = text/x-csharp
$0.CSharpFormattingPolicy = $2
$2.inheritsSet = Mono
$2.inheritsScope = text/x-csharp
$2.scope = text/x-csharp
$0.TextStylePolicy = $3
$3.inheritsSet = VisualStudio
$3.inheritsScope = text/plain
$3.scope = text/plain
$0.TextStylePolicy = $4
$4.inheritsSet = null
$4.scope = application/xml
$0.XmlFormattingPolicy = $5
$5.inheritsSet = Mono
$5.inheritsScope = application/xml
$5.scope = application/xml
EndGlobalSection
EndGlobal
8 changes: 8 additions & 0 deletions src/NLog/Internal/MySmtpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ namespace NLog.Internal
/// </summary>
internal class MySmtpClient : SmtpClient, ISmtpClient
{
/// <summary>
/// Initializes a new instance of the <see cref="MySmtpClient" /> class. Always set DeliveryMethod to Network
/// </summary>
public MySmtpClient()
{
DeliveryMethod = SmtpDeliveryMethod.Network;
}

#if NET3_5 || NET2_0 || NETCF2_0 || NETCF3_5 || MONO
/// <summary>
/// Sends a QUIT message to the SMTP server, gracefully ends the TCP connection, and releases all resources used by the current instance of the <see cref="T:System.Net.Mail.SmtpClient"/> class.
Expand Down
72 changes: 72 additions & 0 deletions src/NLog/LayoutRenderers/ActivityIdLayoutRenderer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// Copyright (c) 2004-2011 Jaroslaw Kowalski <jaak@jkowalski.net>
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of Jaroslaw Kowalski nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
// THE POSSIBILITY OF SUCH DAMAGE.
//

namespace NLog.LayoutRenderers
{
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;

/// <summary>
/// Renders Trace.CorrelationManager.ActivityId.
/// </summary>
[LayoutRenderer("activityid")]
public class ActivityIdLayoutRenderer : LayoutRenderer
{
/// <summary>
/// Initializes a new instance of the <see cref="ActivityIdLayoutRenderer" /> class.
/// </summary>
public ActivityIdLayoutRenderer()
{
this.Format = "D";
}

/// <summary>
/// Gets or sets the ActivityId GUID format as accepted by Guid.ToString() method.
/// </summary>
/// <docgen category='Rendering Options' order='10' />
[DefaultValue("D")]
public string Format { get; set; }

/// <summary>
/// Renders a newly generated ActivityId GUID string and appends it to the specified <see cref="StringBuilder" />.
/// </summary>
/// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
/// <param name="logEvent">Logging event.</param>
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
builder.Append(Trace.CorrelationManager.ActivityId.ToString(this.Format));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace NLog.LayoutRenderers.Wrappers
using NLog.Layouts;

/// <summary>
/// Decodes text "encrypted" with ROT-13.
/// Provides a base for wrapper layout renderers.
/// </summary>
/// <remarks>
/// See <a href="http://en.wikipedia.org/wiki/ROT13">http://en.wikipedia.org/wiki/ROT13</a>.
Expand Down
21 changes: 21 additions & 0 deletions src/NLog/LogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,27 @@ public static Logger GetLogger(string name, Type loggerType)
return globalFactory.GetLogger(name, loggerType);
}

/// <summary>
/// Gets the logger named after the class name.
/// </summary>
/// <typeparam name="T">Type of the current class</typeparam>
/// <returns>The logger reference. Multiple calls to <c>GetLogger</c> with the same argument aren't guaranteed to return the same logger reference.</returns>
public static Logger GetLogger<T>()
{
return globalFactory.GetLogger(typeof(T).FullName);
}

/// <summary>
/// Gets the logger named after the class name.
/// </summary>
/// <typeparam name="T">Type of the current class</typeparam>
/// <param name="loggerType">The logger class. The class must inherit from <see cref="Logger" />.</param>
/// <returns>The logger reference. Multiple calls to <c>GetLogger</c> with the same argument aren't guaranteed to return the same logger reference.</returns>
public static Logger GetLogger<T>(Type loggerType)
{
return globalFactory.GetLogger(typeof(T).FullName, loggerType);
}

/// <summary>
/// Loops through all loggers previously returned by GetLogger.
/// and recalculates their target and filter list. Useful after modifying the configuration programmatically
Expand Down
1 change: 1 addition & 0 deletions src/NLog/NLog.netfx20.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
<Compile Include="Internal\Win32ThreadIDHelper.cs" />
<Compile Include="LayoutRenderers\ActivityIdLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\AmbientPropertyAttribute.cs" />
<Compile Include="LayoutRenderers\AspApplicationValueLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\AspRequestValueLayoutRenderer.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/NLog/NLog.netfx35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
<Compile Include="Internal\Win32ThreadIDHelper.cs" />
<Compile Include="LayoutRenderers\ActivityIdLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\AmbientPropertyAttribute.cs" />
<Compile Include="LayoutRenderers\AspApplicationValueLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\AspRequestValueLayoutRenderer.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/NLog/NLog.netfx40.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
<Compile Include="Internal\Win32ThreadIDHelper.cs" />
<Compile Include="LayoutRenderers\ActivityIdLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\AmbientPropertyAttribute.cs" />
<Compile Include="LayoutRenderers\AspApplicationValueLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\AspRequestValueLayoutRenderer.cs" />
Expand Down
9 changes: 8 additions & 1 deletion src/NLog/Targets/DatabaseParameterInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public DatabaseParameterInfo(string parameterName, Layout parameterLayout)
public string Name { get; set; }

/// <summary>
/// Gets or sets the layout that should be use to calcuate the value for the parameter.
/// Gets or sets the layout that should be use to calculate the value for the parameter.
/// </summary>
/// <docgen category='Parameter Options' order='10' />
[RequiredParameter]
Expand All @@ -98,6 +98,13 @@ public DatabaseParameterInfo(string parameterName, Layout parameterLayout)
/// <docgen category='Parameter Options' order='10' />
[DefaultValue(0)]
public byte Scale { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the database parameter is nullable
/// </summary>
/// <docgen category='Parameter Options' order='10' />
[DefaultValue(false)]
public bool Nullable { get; set; }
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/NLog/Targets/DatabaseTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace NLog.Targets
/// <example>
/// <para>
/// The configuration is dependent on the database type, because
/// there are differnet methods of specifying connection string, SQL
/// there are different methods of specifying connection string, SQL
/// command and command parameters.
/// </para>
/// <para>MS SQL Server using System.Data.SqlClient:</para>
Expand Down Expand Up @@ -476,7 +476,15 @@ private void WriteEventToDatabase(LogEventInfo logEvent)

string stringValue = par.Layout.Render(logEvent);

p.Value = stringValue;
if (par.Nullable && string.IsNullOrEmpty(stringValue))
{
p.Value = DBNull.Value;
}
else
{
p.Value = stringValue;
}

command.Parameters.Add(p);

InternalLogger.Trace(" Parameter: '{0}' = '{1}' ({2})", p.ParameterName, p.Value, p.DbType);
Expand Down
4 changes: 2 additions & 2 deletions src/NLog/Targets/TraceTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ public sealed class TraceTarget : TargetWithLayout
{
/// <summary>
/// Writes the specified logging event to the <see cref="System.Diagnostics.Trace"/> facility.
/// If the log level is greater than or equal to <see cref="LogLevel.Error"/> it uses the
/// If the log level is greater than or equal to <see cref="LogLevel.Fatal"/> it uses the
/// <see cref="System.Diagnostics.Trace.Fail(string)"/> method, otherwise it uses
/// <see cref="System.Diagnostics.Trace.Write(string)" /> method.
/// </summary>
/// <param name="logEvent">The logging event.</param>
protected override void Write(LogEventInfo logEvent)
{
if (logEvent.Level >= LogLevel.Error)
if (logEvent.Level >= LogLevel.Fatal)
{
Trace.Fail(this.Layout.Render(logEvent));
}
Expand Down
6 changes: 5 additions & 1 deletion src/VSIntegration/Snippets/CSharpLogger.snippet
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
<ID>LogManager</ID>
<Function>SimpleTypeName(NLog.LogManager)</Function>
</Literal>
<Literal Editable="false">
<ID>ClassName</ID>
<Function>ClassName()</Function>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[private static $Logger$ logger = $LogManager$.GetCurrentClassLogger();]]>
<![CDATA[private static $Logger$ logger = $LogManager$.GetLogger<$ClassName$>();]]>
</Code>
</Snippet>
</CodeSnippet>
Expand Down
2 changes: 1 addition & 1 deletion src/VSIntegration/Snippets/VBLogger.snippet
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<Declarations>
</Declarations>
<Code Language="vb">
<![CDATA[Private logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger()]]>
<![CDATA[Private Shared logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger()]]>
</Code>
</Snippet>
</CodeSnippet>
Expand Down