首次提交
This commit is contained in:
57
MW_Log/01_MW_Log.csproj
Normal file
57
MW_Log/01_MW_Log.csproj
Normal file
@@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{1AC112C4-2400-4D03-A26D-2E3ACE6FE6D4}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>MW_Log</RootNamespace>
|
||||
<AssemblyName>MW_Log</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="log4net">
|
||||
<HintPath>..\DLL\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="LoggerHelper.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="log4net.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
49
MW_Log/LoggerHelper.cs
Normal file
49
MW_Log/LoggerHelper.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using log4net;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MW_Log
|
||||
{
|
||||
/// <summary>
|
||||
/// LoggerHelper
|
||||
/// </summary>
|
||||
public class LoggerHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// LogInfo
|
||||
/// </summary>
|
||||
private static readonly ILog LogInfo = LogManager.GetLogger("LogInfo");
|
||||
/// <summary>
|
||||
/// 记录Info日志
|
||||
/// </summary>
|
||||
/// <param name="msg"></param>
|
||||
/// <param name="ex"></param>
|
||||
public static void Info(string type, string msg, Exception ex = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
msg = $"【类别:{type}】\r\n【内容】:{msg}";
|
||||
if (ex != null)
|
||||
{
|
||||
LogInfo.Info(msg, ex);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogInfo.Info(msg);
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
37
MW_Log/Properties/AssemblyInfo.cs
Normal file
37
MW_Log/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("MW_Log")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("MW_Log")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2023")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("1ac112c4-2400-4d03-a26d-2e3ace6fe6d4")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
|
||||
//通过使用 "*",如下所示:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", ConfigFileExtension = "config", Watch = true)]
|
||||
BIN
MW_Log/_codex_verify/MW_Log.dll
Normal file
BIN
MW_Log/_codex_verify/MW_Log.dll
Normal file
Binary file not shown.
35
MW_Log/_codex_verify/log4net.config
Normal file
35
MW_Log/_codex_verify/log4net.config
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
|
||||
</configSections>
|
||||
<log4net>
|
||||
<!--Info日志-->
|
||||
<appender name="InfoAppender" type="log4net.Appender.RollingFileAppender">
|
||||
<!--日志文件存放位置,可以为绝对路径也可以为相对路径 -->
|
||||
<param name="File" value="C:\MWLOG" />
|
||||
<!--是否支持分割文件-->
|
||||
<param name="AppendToFile" value="true" />
|
||||
<param name="MaxFileSize" value="10240" />
|
||||
<!--当日志文件达到MaxFileSize大小,就自动创建备份文件。-->
|
||||
<param name="MaxSizeRollBackups" value="100" />
|
||||
<!-- 当将日期作为日志文件的名字时,必须将staticLogFileName的值设置为false -->
|
||||
<param name="StaticLogFileName" value="false" />
|
||||
<!-- 日志文件的命名规则 -->
|
||||
<param name="DatePattern" value="\\yyyy_MM\\yyyy_MM_dd'.log'" />
|
||||
<!--日志文件的记录形式-->
|
||||
<param name="RollingStyle" value="Date" />
|
||||
<!--日志文件的布局格式:%newline【%date】【级别:%-5level】【线程ID:%thread】%n【内容】:%message%newline %n%n-->
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="【%date】【线程ID:%thread】%message%newline %n%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!--Info日志-->
|
||||
<logger name="LogInfo">
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="InfoAppender" />
|
||||
</logger>
|
||||
|
||||
</log4net>
|
||||
</configuration>
|
||||
BIN
MW_Log/_codex_verify/log4net.dll
Normal file
BIN
MW_Log/_codex_verify/log4net.dll
Normal file
Binary file not shown.
35
MW_Log/log4net.config
Normal file
35
MW_Log/log4net.config
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
|
||||
</configSections>
|
||||
<log4net>
|
||||
<!--Info日志-->
|
||||
<appender name="InfoAppender" type="log4net.Appender.RollingFileAppender">
|
||||
<!--日志文件存放位置,可以为绝对路径也可以为相对路径 -->
|
||||
<param name="File" value="C:\MWLOG" />
|
||||
<!--是否支持分割文件-->
|
||||
<param name="AppendToFile" value="true" />
|
||||
<param name="MaxFileSize" value="10240" />
|
||||
<!--当日志文件达到MaxFileSize大小,就自动创建备份文件。-->
|
||||
<param name="MaxSizeRollBackups" value="100" />
|
||||
<!-- 当将日期作为日志文件的名字时,必须将staticLogFileName的值设置为false -->
|
||||
<param name="StaticLogFileName" value="false" />
|
||||
<!-- 日志文件的命名规则 -->
|
||||
<param name="DatePattern" value="\\yyyy_MM\\yyyy_MM_dd'.log'" />
|
||||
<!--日志文件的记录形式-->
|
||||
<param name="RollingStyle" value="Date" />
|
||||
<!--日志文件的布局格式:%newline【%date】【级别:%-5level】【线程ID:%thread】%n【内容】:%message%newline %n%n-->
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="【%date】【线程ID:%thread】%message%newline %n%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!--Info日志-->
|
||||
<logger name="LogInfo">
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="InfoAppender" />
|
||||
</logger>
|
||||
|
||||
</log4net>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user