SVN r1066

SVN-Revision: r1066
This commit is contained in:
tdx
2025-12-03 03:18:14 +00:00
parent 149ae2cec6
commit 1536d4dc5f
3 changed files with 229 additions and 1 deletions
+143
View File
@@ -0,0 +1,143 @@
using Common.Logging;
using Lskj.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Lskj.Util
{
public static class LoggerHandler
{
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public static void Debug(this object happenobj, object message)
{
if (log.IsDebugEnabled)
{
try
{
log.Debug(new LogInfo(happenobj) { msg = message });
}
catch (Exception e)
{
Error(message, e);
}
}
}
public static void Debug(this object happenobj, object message, Exception exception)
{
if (log.IsDebugEnabled)
try
{
log.Debug(new LogInfo(happenobj) { msg = message, exception = exception });
}
catch (Exception e)
{
Error(message, e);
}
}
public static void Error(this object happenobj, object message)
{
if (log.IsErrorEnabled)
try
{
log.Error(new LogInfo(happenobj) { msg = message });
}
catch (Exception e)
{
Error(message, e);
}
}
public static void Error(this object happenobj, object message, Exception exception)
{
if (log.IsErrorEnabled)
try
{
log.Error(new LogInfo(happenobj) { msg = message, exception = exception });
}
catch { }
}
public static void Fatal(this object happenobj, object message)
{
if (log.IsFatalEnabled)
try
{
log.Fatal(new LogInfo(happenobj) { msg = message });
}
catch (Exception e)
{
Error(message, e);
}
}
public static void Fatal(this object happenobj, object message, Exception exception)
{
if (log.IsFatalEnabled)
try
{
log.Fatal(new LogInfo(happenobj) { msg = message, exception = exception });
}
catch (Exception e)
{
Error(message, e);
}
}
public static void Info(this object happenobj, object message)
{
if (log.IsInfoEnabled)
try
{
log.Info(new LogInfo(happenobj) { msg = message });
}
catch (Exception e)
{
Error(message, e);
}
}
public static void Info(this object happenobj, object message, Exception exception)
{
if (log.IsInfoEnabled)
try
{
log.Info(new LogInfo(happenobj) { msg = message, exception = exception });
}
catch (Exception e)
{
Error(message, e);
}
}
public static void Warn(this object happenobj, object message)
{
if (log.IsWarnEnabled)
try
{
log.Warn(new LogInfo(happenobj) { msg = message });
}
catch (Exception e)
{
Error(message, e);
}
}
public static void Warn(this object happenobj, object message, Exception exception)
{
if (log.IsWarnEnabled)
try
{
log.Warn(new LogInfo(happenobj) { msg = message, exception = exception });
}
catch (Exception e)
{
Error(message, e);
}
}
private st
+46 -1
View File
@@ -18,7 +18,7 @@
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
@@ -41,7 +41,38 @@
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile>..\..\Debug\AllMethodXml\Lskj.Util.XML</DocumentationFile>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<PlatformTarget>AnyCPU</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="Common.Logging, Version=3.4.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\引用DLL\Common.Logging.dll</HintPath>
</Reference>
<Reference Include="Common.Logging.Core, Version=3.4.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\引用DLL\Common.Logging.Core.dll</HintPath>
</Reference>
<Reference Include="Common.Logging.Log4Net208, Version=3.4.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\引用DLL\Common.Logging.Log4Net208.dll</HintPath>
</Reference>
<Reference Include="DevExpress.XtraTreeList.v15.2, Version=15.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files\DevExpress 15.2\Components\Bin\Framework\DevExpress.XtraTreeList.v15.2.dll</HintPath>
@@ -69,9 +100,21 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\引用DLL\GpyApi\IKVM.Runtime.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\引用DLL\log4net.dll</HintPath>
</Reference>
<Reference Include="Lskj.Expression">
<HintPath>..\..\引用DLL\Lskj.Expression.dll</HintPath>
</Reference>
<Reference Include="Lskj.Web.Core, Version=1.0.0.1, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\引用DLL\Lskj.Web.Core.dll</HintPath>
</Reference>
<Reference Include="Lskj.WebErp.Core, Version=1.0.9.4, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\引用DLL\Lskj.WebErp.Core.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.1.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\引用DLL\Newtonsoft.Json.dll</HintPath>
@@ -134,6 +177,8 @@
<Compile Include="IniHelper.cs" />
<Compile Include="JsonUtil.cs" />
<Compile Include="LogHelper.cs" />
<Compile Include="LoggerHandler.cs" />
<Compile Include="MyLayout.cs" />
<Compile Include="NumToUpper.cs" />
<Compile Include="Publentry.cs" />
<Compile Include="PwdStrengthHelp.cs" />
+40
View File
@@ -0,0 +1,40 @@
using log4net.Layout;
using log4net.Layout.Pattern;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace Lskj.Util
{
public class MyLayout : PatternLayout
{
public MyLayout()
{
this.AddConverter("property", typeof(MyPatternConverter));
}
}
public class MyPatternConverter : PatternLayoutConverter
{
protected override void Convert(System.IO.TextWriter writer, log4net.Core.LoggingEvent loggingEvent)
{
if (Option != null)
{
WriteObject(writer, loggingEvent.Repository, LookupProperty(Option, loggingEvent));
}
else
{
// 写入所有关键值对
WriteDictionary(writer, loggingEvent.