diff --git a/NLogC.sln b/NLogC.sln index 0ba2edde..6d73a8ab 100644 --- a/NLogC.sln +++ b/NLogC.sln @@ -7,10 +7,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NLog", "src\NLog\NLog.cspro ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NLogCTest", "src\NLogCTest\NLogCTest.vcproj", "{3A3B8573-0A64-414D-9E8D-9F1982004299}" + ProjectSection(ProjectDependencies) = postProject + {63966F8B-B3DA-4538-AF36-FCBBFFF67BF7} = {63966F8B-B3DA-4538-AF36-FCBBFFF67BF7} + {020354EE-5073-4BB5-9AA2-A7EADA8CAD09} = {020354EE-5073-4BB5-9AA2-A7EADA8CAD09} + EndProjectSection +EndProject Global - GlobalSection(DPCodeReviewSolutionGUID) = preSolution - DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} - EndGlobalSection GlobalSection(SolutionConfiguration) = preSolution Debug = Debug Release = Release @@ -24,9 +27,16 @@ Global {020354EE-5073-4BB5-9AA2-A7EADA8CAD09}.Debug.Build.0 = Debug|.NET {020354EE-5073-4BB5-9AA2-A7EADA8CAD09}.Release.ActiveCfg = Release|.NET {020354EE-5073-4BB5-9AA2-A7EADA8CAD09}.Release.Build.0 = Release|.NET + {3A3B8573-0A64-414D-9E8D-9F1982004299}.Debug.ActiveCfg = Debug|Win32 + {3A3B8573-0A64-414D-9E8D-9F1982004299}.Debug.Build.0 = Debug|Win32 + {3A3B8573-0A64-414D-9E8D-9F1982004299}.Release.ActiveCfg = Release|Win32 + {3A3B8573-0A64-414D-9E8D-9F1982004299}.Release.Build.0 = Release|Win32 EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EndGlobalSection GlobalSection(ExtensibilityAddIns) = postSolution EndGlobalSection + GlobalSection(DPCodeReviewSolutionGUID) = preSolution + DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} + EndGlobalSection EndGlobal diff --git a/src/NLog.ComInterop/AssemblyInfo.cs b/src/NLog.ComInterop/AssemblyInfo.cs index 734ea416..4240d6cd 100644 --- a/src/NLog.ComInterop/AssemblyInfo.cs +++ b/src/NLog.ComInterop/AssemblyInfo.cs @@ -32,9 +32,20 @@ // THE POSSIBILITY OF SUCH DAMAGE. // +using System; using System.Reflection; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; -[assembly: AssemblyTitle("NLog.ComInterop")][assembly: AssemblyDescription("NLog COM Interop")][assembly: AssemblyConfiguration("")][assembly: AssemblyCompany("NLog")][assembly: AssemblyProduct("NLog - .NET Logging Library")][assembly: AssemblyCopyright("Copyright (c) 2004 by Jaroslaw Kowalski")][assembly: AssemblyCulture("")] +[assembly: AssemblyTitle("NLog.ComInterop")] +[assembly: AssemblyDescription("NLog COM Interop")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("NLog")] +[assembly: AssemblyProduct("NLog - .NET Logging Library")] +[assembly: AssemblyCopyright("Copyright (c) 2004 by Jaroslaw Kowalski")] +[assembly: AssemblyCulture("")] [assembly: AssemblyVersion("0.3.0.0")] + +[assembly: Guid("fb84adc2-a04b-4ff3-8a20-7c069c3cfa6f")] + diff --git a/src/NLog.ComInterop/ILogManager.cs b/src/NLog.ComInterop/ILogManager.cs new file mode 100644 index 00000000..b7a60388 --- /dev/null +++ b/src/NLog.ComInterop/ILogManager.cs @@ -0,0 +1,49 @@ +// +// Copyright (c) 2004 Jaroslaw Kowalski +// +// +// 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 the 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. +// + +using System; +using System.Runtime.InteropServices; + +namespace NLog.ComInterop +{ + [Guid("7ee3af3b-ba37-45b6-8f5d-cc23bb46c698")] + [InterfaceType(ComInterfaceType.InterfaceIsDual)] + public interface ILogManager + { + void LoadConfigFromFile(string fileName); + bool InternalLogToConsole { get; set; } + string InternalLogFile { get; set; } + string InternalLogLevel { get; set; } + } +} diff --git a/src/NLog.ComInterop/ILogger.cs b/src/NLog.ComInterop/ILogger.cs index 9554354e..15b77cbb 100644 --- a/src/NLog.ComInterop/ILogger.cs +++ b/src/NLog.ComInterop/ILogger.cs @@ -33,9 +33,12 @@ // using System; +using System.Runtime.InteropServices; namespace NLog.ComInterop { + [Guid("757fd55a-cc93-4b53-a7a0-18e85620704a")] + [InterfaceType(ComInterfaceType.InterfaceIsDual)] public interface ILogger { void Log(string level, string message); @@ -66,5 +69,10 @@ bool IsFatalEnabled { get; } + + string LoggerName + { + get; set; + } } } diff --git a/src/NLog.ComInterop/LogManager.cs b/src/NLog.ComInterop/LogManager.cs new file mode 100644 index 00000000..4ee388ff --- /dev/null +++ b/src/NLog.ComInterop/LogManager.cs @@ -0,0 +1,73 @@ +// +// Copyright (c) 2004 Jaroslaw Kowalski +// +// +// 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 the 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. +// + +using System; +using System.Runtime.InteropServices; + +using NLog; +using NLog.Internal; +using NLog.Config; + +namespace NLog.ComInterop +{ + [ComVisible(true)] + [ProgId("NLog.LogManager")] + [Guid("9a7e8d84-72e4-478a-9a05-23c7ef0cfca8")] + [ClassInterface(ClassInterfaceType.None)] + public class LogManager: ILogManager + { + public void LoadConfigFromFile(string fileName) + { + NLog.LogManager.Configuration = new XmlLoggingConfiguration(fileName); + } + + public bool InternalLogToConsole + { + get { return NLog.Internal.InternalLogger.LogToConsole; } + set { NLog.Internal.InternalLogger.LogToConsole = value; } + } + + public string InternalLogLevel + { + get { return NLog.Internal.InternalLogger.LogLevel.ToString(); } + set { NLog.Internal.InternalLogger.LogLevel = NLog.Logger.LogLevelFromString(value); } + } + + public string InternalLogFile + { + get { return NLog.Internal.InternalLogger.LogFile; } + set { NLog.Internal.InternalLogger.LogFile = value; } + } + } +} diff --git a/src/NLog.ComInterop/Logger.cs b/src/NLog.ComInterop/Logger.cs index 6b310776..1ec08005 100644 --- a/src/NLog.ComInterop/Logger.cs +++ b/src/NLog.ComInterop/Logger.cs @@ -40,7 +40,10 @@ namespace NLog.ComInterop { - [ComVisible(true)][ProgId("NLog.Logger")] + [ComVisible(true)] + [ProgId("NLog.Logger")] + [Guid("181f39a8-41a8-4e35-91b6-5f8d96f5e61c")] + [ClassInterface(ClassInterfaceType.None)] public class Logger: ILogger { private static NLog.Logger _defaultLogger = new NullLogger(); diff --git a/src/NLog.ComInterop/NLog.ComInterop.csproj b/src/NLog.ComInterop/NLog.ComInterop.csproj index 19fa4a8d..1e7b9a6b 100644 --- a/src/NLog.ComInterop/NLog.ComInterop.csproj +++ b/src/NLog.ComInterop/NLog.ComInterop.csproj @@ -37,7 +37,7 @@ NoWarn = "" Optimize = "false" OutputPath = "bin\Debug\" - RegisterForComInterop = "false" + RegisterForComInterop = "true" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "1" @@ -57,7 +57,7 @@ NoWarn = "" Optimize = "false" OutputPath = "bin\Release\" - RegisterForComInterop = "false" + RegisterForComInterop = "true" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "1" @@ -98,11 +98,21 @@ SubType = "Code" BuildAction = "Compile" /> + + diff --git a/src/NLog.Test/App.config b/src/NLog.Test/App.config index 17c961d4..b9a353f8 100644 --- a/src/NLog.Test/App.config +++ b/src/NLog.Test/App.config @@ -38,7 +38,8 @@ - + + diff --git a/src/NLog.Test/Test.cs b/src/NLog.Test/Test.cs index cbe22769..4e31f026 100644 --- a/src/NLog.Test/Test.cs +++ b/src/NLog.Test/Test.cs @@ -45,8 +45,8 @@ public static void LogProc(string msg) } static void Main(string[]args) { - Console.WriteLine("zzz"); - NLog.LogManager.Configuration = new XmlLoggingConfiguration("NLog.Test.exe.config"); + //NLog.LogManager.Configuration = new XmlLoggingConfiguration("NLog.Test.exe.config"); + Logger l0 = LogManager.GetCurrentClassLogger(); NLog.Logger l = NLog.LogManager.GetLogger("Aaa"); NLog.Logger l2 = NLog.LogManager.GetLogger("Bbb"); @@ -73,5 +73,6 @@ static void Main(string[]args) l.Fatal("this is a fatal"); l2.Error("this is an error"); l2.Fatal("this is a fatal"); + l0.Debug("Class logger!"); } } diff --git a/src/NLog/AssemblyInfo.cs b/src/NLog/AssemblyInfo.cs index 97129d5c..4b76f484 100644 --- a/src/NLog/AssemblyInfo.cs +++ b/src/NLog/AssemblyInfo.cs @@ -52,7 +52,7 @@ [assembly: ComVisible(false)] #if !NETCF -[assembly: ReflectionPermission(SecurityAction.RequestMinimum, MemberAccess = true, TypeInformation = true)] -[assembly: SecurityPermission(SecurityAction.RequestMinimum, Flags = SecurityPermissionFlag.Execution)] -[assembly: FileIOPermission(SecurityAction.RequestMinimum, Unrestricted = true)] +//[assembly: ReflectionPermission(SecurityAction.RequestMinimum, MemberAccess = true, TypeInformation = true)] +//[assembly: SecurityPermission(SecurityAction.RequestMinimum, Flags = SecurityPermissionFlag.Execution)] +//[assembly: FileIOPermission(SecurityAction.RequestMinimum, Unrestricted = true)] #endif diff --git a/src/NLog/Config/ConfigSectionHandler.cs b/src/NLog/Config/ConfigSectionHandler.cs index 80fc8323..e34401c2 100644 --- a/src/NLog/Config/ConfigSectionHandler.cs +++ b/src/NLog/Config/ConfigSectionHandler.cs @@ -37,6 +37,7 @@ using System; using System.Xml; using System.Configuration; +using System.IO; using NLog.Internal; @@ -50,7 +51,7 @@ public object Create(object parent, object configContext, XmlNode section) { string configFileName = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; - return new XmlLoggingConfiguration(configFileName); + return new XmlLoggingConfiguration((XmlElement)section, configFileName); } catch (Exception ex) { diff --git a/src/NLog/Config/LoggingConfiguration.cs b/src/NLog/Config/LoggingConfiguration.cs index d77d67e1..ca7b7d03 100644 --- a/src/NLog/Config/LoggingConfiguration.cs +++ b/src/NLog/Config/LoggingConfiguration.cs @@ -92,7 +92,7 @@ public virtual ICollection FileNamesToWatch public virtual LoggingConfiguration Reload() { - return null; + return this; } } } diff --git a/src/NLog/Config/XmlLoggingConfiguration.cs b/src/NLog/Config/XmlLoggingConfiguration.cs index b4d512df..2170138b 100644 --- a/src/NLog/Config/XmlLoggingConfiguration.cs +++ b/src/NLog/Config/XmlLoggingConfiguration.cs @@ -69,10 +69,21 @@ public bool AutoReload public XmlLoggingConfiguration(string fileName) { + InternalLogger.Info("Configuring from {0}...", fileName); _originalFileName = fileName; ConfigureFromFile(fileName); } + public XmlLoggingConfiguration(XmlElement configElement, string fileName) + { + InternalLogger.Info("Configuring from an XML element in {0}...", fileName); + string key = Path.GetFullPath(fileName).ToLower(CultureInfo.InvariantCulture); + _visitedFile[key] = key; + + _originalFileName = fileName; + ConfigureFromXmlElement(configElement, Path.GetDirectoryName(fileName)); + } + public override ICollection FileNamesToWatch { get diff --git a/src/NLog/Internal/EnvironmentHelper.cs b/src/NLog/Internal/EnvironmentHelper.cs new file mode 100644 index 00000000..22434f80 --- /dev/null +++ b/src/NLog/Internal/EnvironmentHelper.cs @@ -0,0 +1,57 @@ +// +// Copyright (c) 2004 Jaroslaw Kowalski +// +// +// 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 the 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. +// + +using System; +using System.Security; + +namespace NLog.Internal +{ + internal sealed class EnvironmentHelper + { + private EnvironmentHelper(){} + + public static string GetSafeEnvironmentVariable(string name) + { + try + { + return Environment.GetEnvironmentVariable(name); + } + catch (SecurityException ex) + { + return null; + } + } + + } +} diff --git a/src/NLog/Internal/InternalLogger.cs b/src/NLog/Internal/InternalLogger.cs index 4d466ef7..6afb126a 100644 --- a/src/NLog/Internal/InternalLogger.cs +++ b/src/NLog/Internal/InternalLogger.cs @@ -92,15 +92,15 @@ static InternalLogger() { try { - if (Environment.GetEnvironmentVariable("NLOG_INTERNAL_LOG_TO_CONSOLE") != null) + if (EnvironmentHelper.GetSafeEnvironmentVariable("NLOG_INTERNAL_LOG_TO_CONSOLE") != null) { LogToConsole = true; } - if (Environment.GetEnvironmentVariable("NLOG_INTERNAL_LOG_LEVEL") != null) + if (EnvironmentHelper.GetSafeEnvironmentVariable("NLOG_INTERNAL_LOG_LEVEL") != null) { LogLevel = Logger.LogLevelFromString(Environment.GetEnvironmentVariable("NLOG_INTERNAL_LOG_LEVEL")); } - _logFile = Environment.GetEnvironmentVariable("NLOG_INTERNAL_LOG_FILE"); + _logFile = EnvironmentHelper.GetSafeEnvironmentVariable("NLOG_INTERNAL_LOG_FILE"); Info("NLog internal logger initialized."); } catch {} diff --git a/src/NLog/Internal/MultiFileWatcher.cs b/src/NLog/Internal/MultiFileWatcher.cs index 41cbf006..5fd4effe 100644 --- a/src/NLog/Internal/MultiFileWatcher.cs +++ b/src/NLog/Internal/MultiFileWatcher.cs @@ -68,10 +68,10 @@ public void StopWatching() { foreach (FileSystemWatcher watcher in _watchers) { - Console.WriteLine("releasing watch path: {0} filter: {1}", watcher.Path, watcher.Filter); + //Console.WriteLine("releasing watch path: {0} filter: {1}", watcher.Path, watcher.Filter); watcher.EnableRaisingEvents = false; watcher.Dispose(); - Console.WriteLine("aa"); + //Console.WriteLine("aa"); } _watchers.Clear(); _triggerred = false; diff --git a/src/NLog/Layout.cs b/src/NLog/Layout.cs index d901fe91..4c8195d0 100644 --- a/src/NLog/Layout.cs +++ b/src/NLog/Layout.cs @@ -36,6 +36,7 @@ using System.Text; using System.Collections; +using NLog.Internal; using NLog.LayoutAppenders; namespace NLog @@ -75,15 +76,35 @@ public string GetFormattedMessage(LogEventInfo ev) foreach (LayoutAppender app in _layoutAppenders) { - int ebs = app.GetEstimatedBufferSize(ev); - size += ebs; + try + { + int ebs = app.GetEstimatedBufferSize(ev); + size += ebs; + } + catch (Exception ex) + { + if (InternalLogger.IsWarnEnabled) + { + InternalLogger.Warn("Exception in {0}.GetEstimatedBufferSize(): {1}.", app.GetType().FullName, ex); + } + } } StringBuilder builder = new StringBuilder(size); foreach (LayoutAppender app in _layoutAppenders) { - app.Append(builder, ev); + try + { + app.Append(builder, ev); + } + catch (Exception ex) + { + if (InternalLogger.IsWarnEnabled) + { + InternalLogger.Warn("Exception in {0}.Append(): {1}.", app.GetType().FullName, ex); + } + } } return builder.ToString(); diff --git a/src/NLog/LayoutAppenders/Environment.cs b/src/NLog/LayoutAppenders/Environment.cs index c3359a58..d4b8cd8b 100644 --- a/src/NLog/LayoutAppenders/Environment.cs +++ b/src/NLog/LayoutAppenders/Environment.cs @@ -39,6 +39,7 @@ using System.IO; using NLog.Config; +using NLog.Internal; namespace NLog.LayoutAppenders { @@ -69,7 +70,7 @@ protected internal override void Append(StringBuilder builder, LogEventInfo ev) { if (_variable != null) { - builder.Append(ApplyPadding(Environment.GetEnvironmentVariable(_variable))); + builder.Append(ApplyPadding(EnvironmentHelper.GetSafeEnvironmentVariable(_variable))); } } } diff --git a/src/NLog/LayoutAppenders/MachineName.cs b/src/NLog/LayoutAppenders/MachineName.cs index 952e0901..9dea2dcb 100644 --- a/src/NLog/LayoutAppenders/MachineName.cs +++ b/src/NLog/LayoutAppenders/MachineName.cs @@ -37,12 +37,15 @@ using System; using System.Text; using System.IO; +using NLog.Internal; namespace NLog.LayoutAppenders { [LayoutAppender("machinename")] public class MachineNameLayoutAppender: LayoutAppender { + static string _machineName = GetMachineName(); + protected internal override int GetEstimatedBufferSize(LogEventInfo ev) { return 32; @@ -50,7 +53,20 @@ protected internal override int GetEstimatedBufferSize(LogEventInfo ev) protected internal override void Append(StringBuilder builder, LogEventInfo ev) { - builder.Append(ApplyPadding(Environment.MachineName)); + builder.Append(ApplyPadding(_machineName)); + } + + private static string GetMachineName() + { + try + { + return Environment.MachineName; + } + catch (Exception ex) + { + InternalLogger.Warn("Error getting machine name: {0}", ex); + return String.Empty; + } } } } diff --git a/src/NLog/LogManager.cs b/src/NLog/LogManager.cs index 6808080a..f5b56bea 100644 --- a/src/NLog/LogManager.cs +++ b/src/NLog/LogManager.cs @@ -38,6 +38,8 @@ using System.IO; using System.Reflection; using System.Threading; +using System.Diagnostics; +using System.Security; using NLog.Config; using NLog.Internal; @@ -82,6 +84,14 @@ public static bool ThrowExceptions private LogManager(){} + public static Logger GetCurrentClassLogger() + { + StackTrace st = new StackTrace(false); + StackFrame frame = st.GetFrame(1); + + return GetLogger(frame.GetMethod().DeclaringType.FullName); + } + /// /// Gets the specified named logger. /// @@ -154,7 +164,7 @@ public static LoggingConfiguration Configuration if (_config == null) { - if (Environment.GetEnvironmentVariable("NLOG_GLOBAL_CONFIG_FILE") != null) + if (EnvironmentHelper.GetSafeEnvironmentVariable("NLOG_GLOBAL_CONFIG_FILE") != null) { string configFile = Environment.GetEnvironmentVariable("NLOG_GLOBAL_CONFIG_FILE"); if (File.Exists(configFile)) @@ -200,7 +210,14 @@ public static LoggingConfiguration Configuration set { #if !NETCF - _watcher.StopWatching(); + try + { + _watcher.StopWatching(); + } + catch (Exception ex) + { + InternalLogger.Error("Cannot stop file watching: {0}", ex); + } #endif lock(typeof(LogManager)) @@ -212,7 +229,14 @@ public static LoggingConfiguration Configuration { ReconfigExistingLoggers(_config); #if !NETCF - _watcher.Watch(_config.FileNamesToWatch); + try + { + _watcher.Watch(_config.FileNamesToWatch); + } + catch (Exception ex) + { + InternalLogger.Warn("Cannot start file watching: {0}", ex); + } #endif } } diff --git a/src/NLog/NLog.csproj b/src/NLog/NLog.csproj index 423a3b63..33e587c1 100644 --- a/src/NLog/NLog.csproj +++ b/src/NLog/NLog.csproj @@ -333,6 +333,11 @@ SubType = "Code" BuildAction = "Compile" /> + #include "NLogC.h" +#include + #define NLOG_BUFFER_SIZE 8192 #pragma managed @@ -9,7 +11,7 @@ static void WriteToA(NLogLevel level, LPCSTR loggerName, LPCSTR messageBuffer) { NLog::Logger *logger = NLog::LogManager::GetLogger(loggerName); - logger->Log((NLog::LogLevel)(int)level, messageBuffer); + logger->Log((NLog::LogLevel)(int)level, messageBuffer); } static void WriteToW(NLogLevel level, LPCWSTR loggerName, LPCWSTR messageBuffer) @@ -18,151 +20,183 @@ static void WriteToW(NLogLevel level, LPCWSTR loggerName, LPCWSTR messageBuffer) logger->Log((NLog::LogLevel)(int)level, messageBuffer); } +static bool IsLogEnabledA(NLogLevel level, LPCSTR loggerName) +{ + NLog::Logger *logger = NLog::LogManager::GetLogger(loggerName); + return logger->IsEnabled((NLog::LogLevel)(int)level); +} + +static bool IsLogEnabledW(NLogLevel level, LPCWSTR loggerName) +{ + NLog::Logger *logger = NLog::LogManager::GetLogger(loggerName); + return logger->IsEnabled((NLog::LogLevel)(int)level); +} + +static BOOL ConfigureFromFileA(LPCSTR fileName) +{ + try + { + NLog::LogManager::Configuration = new NLog::Config::XmlLoggingConfiguration(fileName); + return TRUE; + } + catch (System::Exception *) + { + return FALSE; + } +} + +static BOOL ConfigureFromFileW(LPCWSTR fileName) +{ + try + { + NLog::LogManager::Configuration = new NLog::Config::XmlLoggingConfiguration(fileName); + return TRUE; + } + catch (System::Exception *) + { + return FALSE; + } +} + #pragma unmanaged NLOGC_API void NLog_DebugA(LPCSTR loggerName, LPCSTR logMessage, ...) { - char messageBuffer[NLOG_BUFFER_SIZE]; va_list args; - va_start(args, loggerName); - _vsnprintf(messageBuffer, sizeof(messageBuffer), logMessage, args); + NLog_LogVA(NLOG_DEBUG, loggerName, logMessage, args); va_end(args); - WriteToA(NLOG_DEBUG, loggerName, messageBuffer); } NLOGC_API void NLog_InfoA(LPCSTR loggerName, LPCSTR logMessage, ...) { - char messageBuffer[NLOG_BUFFER_SIZE]; va_list args; - va_start(args, loggerName); - _vsnprintf(messageBuffer, sizeof(messageBuffer), logMessage, args); + NLog_LogVA(NLOG_INFO, loggerName, logMessage, args); va_end(args); - WriteToA(NLOG_INFO, loggerName, messageBuffer); } NLOGC_API void NLog_WarnA(LPCSTR loggerName, LPCSTR logMessage, ...) { - char messageBuffer[NLOG_BUFFER_SIZE]; va_list args; - va_start(args, loggerName); - _vsnprintf(messageBuffer, sizeof(messageBuffer), logMessage, args); + NLog_LogVA(NLOG_WARN, loggerName, logMessage, args); va_end(args); - WriteToA(NLOG_WARN, loggerName, messageBuffer); } NLOGC_API void NLog_ErrorA(LPCSTR loggerName, LPCSTR logMessage, ...) { - char messageBuffer[NLOG_BUFFER_SIZE]; va_list args; - va_start(args, loggerName); - _vsnprintf(messageBuffer, sizeof(messageBuffer), logMessage, args); + NLog_LogVA(NLOG_ERROR, loggerName, logMessage, args); va_end(args); - WriteToA(NLOG_ERROR, loggerName, messageBuffer); } NLOGC_API void NLog_FatalA(LPCSTR loggerName, LPCSTR logMessage, ...) { - char messageBuffer[NLOG_BUFFER_SIZE]; va_list args; - va_start(args, loggerName); - _vsnprintf(messageBuffer, sizeof(messageBuffer), logMessage, args); + NLog_LogVA(NLOG_FATAL, loggerName, logMessage, args); va_end(args); - WriteToA(NLOG_FATAL, loggerName, messageBuffer); } NLOGC_API void NLog_LogA(NLogLevel level, LPCSTR loggerName, LPCSTR logMessage, ...) { - char messageBuffer[NLOG_BUFFER_SIZE]; va_list args; - va_start(args, loggerName); - _vsnprintf(messageBuffer, sizeof(messageBuffer), logMessage, args); + NLog_LogVA(level, loggerName, logMessage, args); va_end(args); - WriteToA(level, loggerName, messageBuffer); } NLOGC_API void NLog_LogVA(NLogLevel level, LPCSTR loggerName, LPCSTR logMessage, va_list args) { - char messageBuffer[NLOG_BUFFER_SIZE]; - _vsnprintf(messageBuffer, sizeof(messageBuffer), logMessage, args); - WriteToA(level, loggerName, messageBuffer); + if (0 != strchr(logMessage, '%')) + { + if (IsLogEnabledA(level, loggerName)) + { + char messageBuffer[NLOG_BUFFER_SIZE]; + _vsnprintf(messageBuffer, sizeof(messageBuffer), logMessage, args); + WriteToA(level, loggerName, messageBuffer); + } + } + else + { + WriteToA(level, loggerName, logMessage); + } } NLOGC_API void NLog_DebugW(LPCWSTR loggerName, LPCWSTR logMessage, ...) { - wchar_t messageBuffer[NLOG_BUFFER_SIZE]; va_list args; - va_start(args, loggerName); - _vsnwprintf(messageBuffer, sizeof(messageBuffer), logMessage, args); + NLog_LogVW(NLOG_DEBUG, loggerName, logMessage, args); va_end(args); - WriteToW(NLOG_DEBUG, loggerName, messageBuffer); } NLOGC_API void NLog_InfoW(LPCWSTR loggerName, LPCWSTR logMessage, ...) { - wchar_t messageBuffer[NLOG_BUFFER_SIZE]; va_list args; - va_start(args, loggerName); - _vsnwprintf(messageBuffer, sizeof(messageBuffer), logMessage, args); + NLog_LogVW(NLOG_INFO, loggerName, logMessage, args); va_end(args); - WriteToW(NLOG_INFO, loggerName, messageBuffer); } NLOGC_API void NLog_WarnW(LPCWSTR loggerName, LPCWSTR logMessage, ...) { - wchar_t messageBuffer[NLOG_BUFFER_SIZE]; va_list args; - va_start(args, loggerName); - _vsnwprintf(messageBuffer, sizeof(messageBuffer), logMessage, args); + NLog_LogVW(NLOG_WARN, loggerName, logMessage, args); va_end(args); - WriteToW(NLOG_WARN, loggerName, messageBuffer); } NLOGC_API void NLog_ErrorW(LPCWSTR loggerName, LPCWSTR logMessage, ...) { - wchar_t messageBuffer[NLOG_BUFFER_SIZE]; va_list args; - va_start(args, loggerName); - _vsnwprintf(messageBuffer, sizeof(messageBuffer), logMessage, args); + NLog_LogVW(NLOG_ERROR, loggerName, logMessage, args); va_end(args); - WriteToW(NLOG_ERROR, loggerName, messageBuffer); } NLOGC_API void NLog_FatalW(LPCWSTR loggerName, LPCWSTR logMessage, ...) { - wchar_t messageBuffer[NLOG_BUFFER_SIZE]; va_list args; - va_start(args, loggerName); - _vsnwprintf(messageBuffer, sizeof(messageBuffer), logMessage, args); + NLog_LogVW(NLOG_FATAL, loggerName, logMessage, args); va_end(args); - WriteToW(NLOG_FATAL, loggerName, messageBuffer); } NLOGC_API void NLog_LogW(NLogLevel level, LPCWSTR loggerName, LPCWSTR logMessage, ...) { - wchar_t messageBuffer[NLOG_BUFFER_SIZE]; va_list args; - va_start(args, loggerName); - _vsnwprintf(messageBuffer, sizeof(messageBuffer), logMessage, args); + NLog_LogVW(level, loggerName, logMessage, args); va_end(args); - WriteToW(level, loggerName, messageBuffer); } NLOGC_API void NLog_LogVW(NLogLevel level, LPCWSTR loggerName, LPCWSTR logMessage, va_list args) { wchar_t messageBuffer[NLOG_BUFFER_SIZE]; - _vsnwprintf(messageBuffer, sizeof(messageBuffer), logMessage, args); - WriteToW(level, loggerName, messageBuffer); + if (0 != wcschr(logMessage, L'%')) + { + if (IsLogEnabledW(level, loggerName)) + { + _vsnwprintf(messageBuffer, sizeof(messageBuffer), logMessage, args); + WriteToW(level, loggerName, messageBuffer); + } + } + else + { + WriteToW(level, loggerName, logMessage); + } +} + +NLOGC_API int NLog_ConfigureFromFileA(LPCSTR fileName) +{ + return ConfigureFromFileA(fileName); +} + +NLOGC_API int NLog_ConfigureFromFileW(LPCWSTR fileName) +{ + return ConfigureFromFileW(fileName); } \ No newline at end of file diff --git a/src/NLogC/NLogC.h b/src/NLogC/NLogC.h index 7b86e0b1..10862468 100644 --- a/src/NLogC/NLogC.h +++ b/src/NLogC/NLogC.h @@ -18,6 +18,7 @@ enum NLogLevel extern "C" { +NLOGC_API int NLog_ConfigureFromFileA(const char *fileName); NLOGC_API void NLog_LogA(NLogLevel level, const char *loggerName, const char *logMessage, ...); NLOGC_API void NLog_DebugA(const char *loggerName, const char *logMessage, ...); NLOGC_API void NLog_InfoA(const char *loggerName, const char *logMessage, ...); @@ -25,6 +26,7 @@ NLOGC_API void NLog_WarnA(const char *loggerName, const char *logMessage, ...); NLOGC_API void NLog_ErrorA(const char *loggerName, const char *logMessage, ...); NLOGC_API void NLog_FatalA(const char *loggerName, const char *logMessage, ...); +NLOGC_API int NLog_ConfigureFromFileW(const wchar_t *fileName); NLOGC_API void NLog_LogW(NLogLevel level, const wchar_t *loggerName, const wchar_t *logMessage, ...); NLOGC_API void NLog_DebugW(const wchar_t *loggerName, const wchar_t *logMessage, ...); NLOGC_API void NLog_InfoW(const wchar_t *loggerName, const wchar_t *logMessage, ...); @@ -44,6 +46,7 @@ NLOGC_API void NLog_LogVW(NLogLevel level, const wchar_t *loggerName, const wcha #define NLog_Warn NLog_WarnW #define NLog_Error NLog_ErrorW #define NLog_Fatal NLog_FatalW +#define NLog_ConfigureFromFile NLog_ConfigureFromFileW #else @@ -53,6 +56,7 @@ NLOGC_API void NLog_LogVW(NLogLevel level, const wchar_t *loggerName, const wcha #define NLog_Warn NLog_WarnA #define NLog_Error NLog_ErrorA #define NLog_Fatal NLog_FatalA +#define NLog_ConfigureFromFile NLog_ConfigureFromFileA #endif diff --git a/src/NLogCTest/AssemblyInfo.cpp b/src/NLogCTest/AssemblyInfo.cpp new file mode 100644 index 00000000..3279e459 --- /dev/null +++ b/src/NLogCTest/AssemblyInfo.cpp @@ -0,0 +1,60 @@ +#include "stdafx.h" + +#using + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; + +// +// 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:AssemblyTitleAttribute("")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("")]; +[assembly:AssemblyCopyrightAttribute("")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project directory. +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly:AssemblyDelaySignAttribute(false)]; +[assembly:AssemblyKeyFileAttribute("")]; +[assembly:AssemblyKeyNameAttribute("")]; + diff --git a/src/NLogCTest/NLogCTest.cpp b/src/NLogCTest/NLogCTest.cpp new file mode 100644 index 00000000..9b523838 --- /dev/null +++ b/src/NLogCTest/NLogCTest.cpp @@ -0,0 +1,76 @@ +#include "stdafx.h" + +#include "NLogC.h" + +int main() +{ + NLog_ConfigureFromFile("config.nlog"); + int repeatCount = 500000; + int t0, t1; + + t0 = GetTickCount(); + for (int i = 0; i < repeatCount; ++i) + { + NLog_DebugA("nnn", "message"); + } + t1 = GetTickCount(); + printf("ANSI: %f nanoseconds per null-log\n", (t1 - t0) * 1000000.0 / repeatCount); + + t0 = GetTickCount(); + for (int i = 0; i < repeatCount; ++i) + { + NLog_DebugA("nnn", "message with %s", "sprintf() formatting"); + } + t1 = GetTickCount(); + printf("ANSI: %f nanoseconds per null-log with sprintf() formatting\n", (t1 - t0) * 1000000.0 / repeatCount); + + t0 = GetTickCount(); + for (int i = 0; i < repeatCount; ++i) + { + NLog_DebugA("rrr", "message"); + } + t1 = GetTickCount(); + printf("ANSI: %f nanoseconds per non-logging\n", (t1 - t0) * 1000000.0 / repeatCount); + + t0 = GetTickCount(); + for (int i = 0; i < repeatCount; ++i) + { + NLog_DebugA("rrr", "message with %s", "stringf() formatting"); + } + t1 = GetTickCount(); + printf("ANSI: %f nanoseconds per non-logging with sprintf() formatting\n", (t1 - t0) * 1000000.0 / repeatCount); + + t0 = GetTickCount(); + for (int i = 0; i < repeatCount; ++i) + { + NLog_DebugW(L"nnn", L"message"); + } + t1 = GetTickCount(); + printf("UNICODE: %f nanoseconds per null-log\n", (t1 - t0) * 1000000.0 / repeatCount); + + t0 = GetTickCount(); + for (int i = 0; i < repeatCount; ++i) + { + NLog_DebugW(L"nnn", L"message with %s", L"stringf() formatting"); + } + t1 = GetTickCount(); + printf("UNICODE: %f nanoseconds per null-logging with sprintf() formatting\n", (t1 - t0) * 1000000.0 / repeatCount); + + t0 = GetTickCount(); + for (int i = 0; i < repeatCount; ++i) + { + NLog_DebugW(L"rrr", L"message"); + } + t1 = GetTickCount(); + printf("UNICODE: %f nanoseconds per non-logging\n", (t1 - t0) * 1000000.0 / repeatCount); + + t0 = GetTickCount(); + for (int i = 0; i < repeatCount; ++i) + { + NLog_DebugW(L"rrr", L"message with %s", L"stringf() formatting"); + } + t1 = GetTickCount(); + printf("UNICODE: %f nanoseconds per non-logging with sprintf() formatting\n", (t1 - t0) * 1000000.0 / repeatCount); + + return 0; +} \ No newline at end of file diff --git a/src/NLogCTest/NLogCTest.vcproj b/src/NLogCTest/NLogCTest.vcproj new file mode 100644 index 00000000..43fc986b --- /dev/null +++ b/src/NLogCTest/NLogCTest.vcproj @@ -0,0 +1,173 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/NLogCTest/ReadMe.txt b/src/NLogCTest/ReadMe.txt new file mode 100644 index 00000000..f140bdf9 --- /dev/null +++ b/src/NLogCTest/ReadMe.txt @@ -0,0 +1,28 @@ +======================================================================== + APPLICATION : NLogCTest Project Overview +======================================================================== + +AppWizard has created this NLogCTest Application for you. + +This file contains a summary of what you will find in each of the files that +make up your NLogCTest application. + +NLogCTest.vcproj + This is the main project file for VC++ projects generated using an Application Wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + Application Wizard. + +NLogCTest.cpp + This is the main application source file. + +AssemblyInfo.cpp + Contains custom attributes for modifying assembly metadata. + +///////////////////////////////////////////////////////////////////////////// +Other notes: + +AppWizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +///////////////////////////////////////////////////////////////////////////// diff --git a/src/NLogCTest/app.ico b/src/NLogCTest/app.ico new file mode 100644 index 00000000..3a5525fd Binary files /dev/null and b/src/NLogCTest/app.ico differ diff --git a/src/NLogCTest/app.rc b/src/NLogCTest/app.rc new file mode 100644 index 00000000..b488dbd9 --- /dev/null +++ b/src/NLogCTest/app.rc @@ -0,0 +1,52 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon placed first or with lowest ID value becomes application icon + +LANGUAGE 9, 1 +#pragma code_page(1252) +1 ICON "app.ico" + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" + "\0" +END + +#endif // APSTUDIO_INVOKED + +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/src/NLogCTest/config.nlog b/src/NLogCTest/config.nlog new file mode 100644 index 00000000..a44ff2c5 --- /dev/null +++ b/src/NLogCTest/config.nlog @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/NLogCTest/resource.h b/src/NLogCTest/resource.h new file mode 100644 index 00000000..1f2251c2 --- /dev/null +++ b/src/NLogCTest/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/src/NLogCTest/stdafx.cpp b/src/NLogCTest/stdafx.cpp new file mode 100644 index 00000000..df8d3dc8 --- /dev/null +++ b/src/NLogCTest/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// NLogCTest.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/src/NLogCTest/stdafx.h b/src/NLogCTest/stdafx.h new file mode 100644 index 00000000..322660e2 --- /dev/null +++ b/src/NLogCTest/stdafx.h @@ -0,0 +1,11 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#include +#include + +#include + +// TODO: reference additional headers your program requires here diff --git a/web/comapi.xml b/web/comapi.xml index de1c6f4d..cad74870 100644 --- a/web/comapi.xml +++ b/web/comapi.xml @@ -3,5 +3,7 @@

COM API

+ +
diff --git a/web/examples/config8.nlog b/web/examples/config8.nlog new file mode 100644 index 00000000..a16cd36c --- /dev/null +++ b/web/examples/config8.nlog @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/web/examples/config8a.nlog b/web/examples/config8a.nlog new file mode 100644 index 00000000..98ce85e8 --- /dev/null +++ b/web/examples/config8a.nlog @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/web/examples/test.js b/web/examples/test.js new file mode 100644 index 00000000..225c9351 --- /dev/null +++ b/web/examples/test.js @@ -0,0 +1,40 @@ +var logmanager = new ActiveXObject("NLog.LogManager"); +WScript.Echo("Loading config from file 'config8.nlog' with internal logging to console..."); +logmanager.InternalLogToConsole = true; +logmanager.InternalLogFile = "internal_log.txt"; +logmanager.InternalLogLevel = "Info"; +logmanager.LoadConfigFromFile("config8.nlog"); + +var logger = new ActiveXObject("NLog.Logger"); +logger.LoggerName = "TestLogger"; +logger.Log("Debug", "This is a debugging message"); +logger.Log("Info", "This is an information message"); +logger.Log("Warn", "This is a warning message"); +logger.Log("Error", "This is an error"); +logger.Log("Fatal", "This is a fatal message"); + +logger.Debug("This is a debugging message"); +logger.Info("This is an information message"); +logger.Warn("This is a warning message"); +logger.Error("This is an error"); +logger.Fatal("This is a fatal message"); + +WScript.Echo("Loading config from file 'config8a.nlog' without internal logging..."); +logmanager.InternalLogToConsole = false; +logmanager.InternalLogFile = "internal_log.txt"; +logmanager.InternalLogLevel = "Fatal"; +logmanager.LoadConfigFromFile("config8a.nlog"); + +logger.Log("Debug", "This is a debugging message"); +logger.Log("Info", "This is an information message"); +logger.Log("Warn", "This is a warning message"); +logger.Log("Error", "This is an error"); +logger.Log("Fatal", "This is a fatal message"); + +logger.Debug("This is a debugging message"); +logger.Info("This is an information message"); +logger.Warn("This is a warning message"); +logger.Error("This is an error"); +logger.Fatal("This is a fatal message"); + + diff --git a/web/examples/test.js.html b/web/examples/test.js.html new file mode 100644 index 00000000..7fe5adee --- /dev/null +++ b/web/examples/test.js.html @@ -0,0 +1,42 @@ +
var logmanager = new ActiveXObject("NLog.LogManager");
+WScript.Echo("Loading config from file 'config8.nlog' with internal logging to console...");
+logmanager.InternalLogToConsole = true;
+logmanager.InternalLogFile = "internal_log.txt";
+logmanager.InternalLogLevel = "Info";
+logmanager.LoadConfigFromFile("config8.nlog");
+
+var logger = new ActiveXObject("NLog.Logger");
+logger.LoggerName = "TestLogger";
+logger.Log("Debug", "This is a debugging message");
+logger.Log("Info", "This is an information message");
+logger.Log("Warn", "This is a warning message");
+logger.Log("Error", "This is an error");
+logger.Log("Fatal", "This is a fatal message");
+
+logger.Debug("This is a debugging message");
+logger.Info("This is an information message");
+logger.Warn("This is a warning message");
+logger.Error("This is an error");
+logger.Fatal("This is a fatal message");
+
+WScript.Echo("Loading config from file 'config8a.nlog' without internal logging...");
+logmanager.InternalLogToConsole = false;
+logmanager.InternalLogFile = "internal_log.txt";
+logmanager.InternalLogLevel = "Fatal";
+logmanager.LoadConfigFromFile("config8a.nlog");
+
+logger.Log("Debug", "This is a debugging message");
+logger.Log("Info", "This is an information message");
+logger.Log("Warn", "This is a warning message");
+logger.Log("Error", "This is an error");
+logger.Log("Fatal", "This is a fatal message");
+
+logger.Debug("This is a debugging message");
+logger.Info("This is an information message");
+logger.Warn("This is a warning message");
+logger.Error("This is an error");
+logger.Fatal("This is a fatal message");
+
+
+
+
\ No newline at end of file diff --git a/web/examples/test.vbs b/web/examples/test.vbs new file mode 100644 index 00000000..adf784e6 --- /dev/null +++ b/web/examples/test.vbs @@ -0,0 +1,42 @@ +Dim logmanager, logger + +Set logmanager = CreateObject("NLog.LogManager") +WScript.Echo "Loading config from file 'config8.nlog' with internal logging to console..." +logmanager.InternalLogToConsole = true +logmanager.InternalLogFile = "internal_log.txt" +logmanager.InternalLogLevel = "Info" +logmanager.LoadConfigFromFile "config8.nlog" + +Set logger = CreateObject("NLog.Logger") +logger.LoggerName = "TestLogger" +logger.Log "Debug", "This is a debugging message" +logger.Log "Info", "This is an information message" +logger.Log "Warn", "This is a warning message" +logger.Log "Error", "This is an error" +logger.Log "Fatal", "This is a fatal message" + +logger.Debug "This is a debugging message" +logger.Info "This is an information message" +logger.Warn "This is a warning message" +logger.Error "This is an error" +logger.Fatal "This is a fatal message" + +WScript.Echo "Loading config from file 'config8a.nlog' without internal logging..." +logmanager.InternalLogToConsole = false +logmanager.InternalLogFile = "internal_log.txt" +logmanager.InternalLogLevel = "Fatal" +logmanager.LoadConfigFromFile "config8a.nlog" + +logger.Log "Debug", "This is a debugging message" +logger.Log "Info", "This is an information message" +logger.Log "Warn", "This is a warning message" +logger.Log "Error", "This is an error" +logger.Log "Fatal", "This is a fatal message" + +logger.Debug "This is a debugging message" +logger.Info "This is an information message" +logger.Warn "This is a warning message" +logger.Error "This is an error" +logger.Fatal "This is a fatal message" + + diff --git a/web/examples/test.vbs.html b/web/examples/test.vbs.html new file mode 100644 index 00000000..2a495dc6 --- /dev/null +++ b/web/examples/test.vbs.html @@ -0,0 +1,44 @@ +
Dim logmanager, logger
+
+Set logmanager = CreateObject("NLog.LogManager")
+WScript.Echo "Loading config from file 'config8.nlog' with internal logging to console..."
+logmanager.InternalLogToConsole = true
+logmanager.InternalLogFile = "internal_log.txt"
+logmanager.InternalLogLevel = "Info"
+logmanager.LoadConfigFromFile "config8.nlog"
+
+Set logger = CreateObject("NLog.Logger")
+logger.LoggerName = "TestLogger"
+logger.Log "Debug", "This is a debugging message"
+logger.Log "Info", "This is an information message"
+logger.Log "Warn", "This is a warning message"
+logger.Log "Error", "This is an error"
+logger.Log "Fatal", "This is a fatal message"
+
+logger.Debug "This is a debugging message"
+logger.Info "This is an information message"
+logger.Warn "This is a warning message"
+logger.Error "This is an error"
+logger.Fatal "This is a fatal message"
+
+WScript.Echo "Loading config from file 'config8a.nlog' without internal logging..."
+logmanager.InternalLogToConsole = false
+logmanager.InternalLogFile = "internal_log.txt"
+logmanager.InternalLogLevel = "Fatal"
+logmanager.LoadConfigFromFile "config8a.nlog"
+
+logger.Log "Debug", "This is a debugging message"
+logger.Log "Info", "This is an information message"
+logger.Log "Warn", "This is a warning message"
+logger.Log "Error", "This is an error"
+logger.Log "Fatal", "This is a fatal message"
+
+logger.Debug "This is a debugging message"
+logger.Info "This is an information message"
+logger.Warn "This is a warning message"
+logger.Error "This is an error"
+logger.Fatal "This is a fatal message"
+
+
+
+
\ No newline at end of file diff --git a/web/examples/tutorial.cs.html b/web/examples/tutorial.cs.html index 7069dcc4..b7c8a68b 100644 --- a/web/examples/tutorial.cs.html +++ b/web/examples/tutorial.cs.html @@ -8,14 +8,14 @@ static void Main() { - // you can use an interface known from log4net + // you can use an interface known from log4net logger.Debug("This is a debugging message"); logger.Info("This is a information message"); logger.Warn("This is a warning message"); logger.Error("This is an error"); logger.Fatal("This is a fatal error message"); - // you can ask if the logging is enabled before writing + // you can ask if the logging is enabled before writing if (logger.IsDebugEnabled) { logger.Debug("Some debug info"); } @@ -23,13 +23,13 @@ // you can use WriteLine() style formatting logger.Debug("The result is {0} {1}", 1 + 2, "zzz"); - // you can even pass IFormatProvider for maximum flexibility + // you can even pass IFormatProvider for maximum flexibility logger.Debug(CultureInfo.InvariantCulture, "The current time is {0}", DateTime.Now); - // you can ask if the logging is enabled for specified level + // you can ask if the logging is enabled for specified level if (logger.IsEnabled(LogLevel.Warn)) { - // and you can write the message for a particular level, too + // and you can write the message for a particular level, too logger.Log(LogLevel.Warn, "Some warning info"); } } diff --git a/web/style.css b/web/style.css index bd6feee9..73c8021c 100644 --- a/web/style.css +++ b/web/style.css @@ -3,7 +3,7 @@ html, body margin-right: 4px; margin-left: 4px; margin-top: 2px; - background: white; + background-color: #fff8f8; color: black; font-family: Verdana; font-size: 70%; @@ -313,7 +313,7 @@ td.controls table.page { width: 800px; - border: 1px solid #404060; + /* border: 1px solid #404060; */ } tr.spacer @@ -394,6 +394,27 @@ td.newstext color: #400000; } +.jscript .k +{ + color: #0000ff; +} + +.jscript .c +{ + color: #008000; + font-style: italic; +} + +.jscript .s +{ + color: #400000; +} + +.jscript .r +{ + color: #400000; +} + code { color: #000080; diff --git a/web/style.xsl b/web/style.xsl index 129b422c..18e3b90e 100644 --- a/web/style.xsl +++ b/web/style.xsl @@ -88,6 +88,13 @@ + +
+            
+        
+ +
+