chore: 初始化合力驱动桥MES采集程序
This commit is contained in:
61
Common/MyLog4Net/00_MyLog4Net.csproj
Normal file
61
Common/MyLog4Net/00_MyLog4Net.csproj
Normal file
@@ -0,0 +1,61 @@
|
||||
<?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>{1DC48C83-1842-4DE8-ACAF-26E1E7F7C58F}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>MyLog4Net</RootNamespace>
|
||||
<AssemblyName>MyLog4Net</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, Version=2.0.14.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\log4net.2.0.14\lib\net45\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Web" />
|
||||
<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="MyLogEventArgs.cs" />
|
||||
<Compile Include="MyLogHelper.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<None Include="log4net.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
14
Common/MyLog4Net/MyLogEventArgs.cs
Normal file
14
Common/MyLog4Net/MyLogEventArgs.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyLog4Net
|
||||
{
|
||||
public class MyLogEventArgs : EventArgs
|
||||
{
|
||||
public string Message { get; set; }
|
||||
public string Module { get; set; }
|
||||
}
|
||||
}
|
||||
65
Common/MyLog4Net/MyLogHelper.cs
Normal file
65
Common/MyLog4Net/MyLogHelper.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using log4net;
|
||||
using System;
|
||||
|
||||
namespace MyLog4Net
|
||||
{
|
||||
public class MyLogHelper
|
||||
{
|
||||
public delegate void MyLogEventHandler(object sender, MyLogEventArgs e);
|
||||
public static event MyLogEventHandler LogCommit;
|
||||
|
||||
/// <summary>
|
||||
/// 普通日志
|
||||
/// </summary>
|
||||
/// <param name="message">日志内容</param>
|
||||
public static void Info(string module, string message)
|
||||
{
|
||||
ILog log = LogManager.GetLogger(module);
|
||||
if (log.IsInfoEnabled)
|
||||
{
|
||||
log.Info(message);
|
||||
|
||||
var e = new MyLogEventArgs();
|
||||
e.Module = module;
|
||||
e.Message = message;
|
||||
LogCommit?.Invoke(null, e);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 错误日志带异常
|
||||
/// </summary>
|
||||
/// <param name="message">错误日志</param>
|
||||
public static void Error(string module, string message, Exception ex)
|
||||
{
|
||||
ILog log = LogManager.GetLogger(module);
|
||||
if (log.IsErrorEnabled)
|
||||
{
|
||||
log.Error(message, ex);
|
||||
|
||||
var e = new MyLogEventArgs();
|
||||
e.Module = module;
|
||||
e.Message = message;
|
||||
LogCommit?.Invoke(null, e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 错误日志不带异常
|
||||
/// </summary>
|
||||
/// <param name="message">错误日志</param>
|
||||
public static void Error(string module, string message)
|
||||
{
|
||||
ILog log = LogManager.GetLogger(module);
|
||||
if (log.IsErrorEnabled)
|
||||
{
|
||||
log.Error(message);
|
||||
|
||||
var e = new MyLogEventArgs();
|
||||
e.Module = module;
|
||||
e.Message = message;
|
||||
LogCommit?.Invoke(null, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
37
Common/MyLog4Net/Properties/AssemblyInfo.cs
Normal file
37
Common/MyLog4Net/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
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("Log4Net")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Log4Net")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2022")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("1dc48c83-1842-4de8-acaf-26e1e7f7c58f")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
|
||||
35
Common/MyLog4Net/log4net.config
Normal file
35
Common/MyLog4Net/log4net.config
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<log4net>
|
||||
<!-- 控制台日志配置 -->
|
||||
<appender name="Console" type="log4net.Appender.ConsoleAppender">
|
||||
<!-- 日志输出格式 -->
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<!--<conversionPattern value="%5level [%thread] (%file:%line) - %message%newline" />-->
|
||||
<conversionPattern value="%date %-5level %thread %logger - %message%newline" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- 文件存储日志配置 -->
|
||||
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
|
||||
<!-- 保存文件的名称 -->
|
||||
<file value="./log/log.log" />
|
||||
<appendToFile value="true" />
|
||||
<!-- 文件的编码方式 -->
|
||||
<param name="Encoding" value="UTF-8"/>
|
||||
<param name="DatePattern" value="'.'yyyy-MM-dd'.log'" />
|
||||
<!-- 每个文件的大小 -->
|
||||
<maximumFileSize value="10000KB" />
|
||||
<!-- 保存文件数量 -->
|
||||
<maxSizeRollBackups value="2" />
|
||||
<!-- 日志输出格式 -->
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date %-5level %thread %logger - %message%newline" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<root>
|
||||
<level value="ALL" />
|
||||
<appender-ref ref="Console" />
|
||||
<appender-ref ref="RollingFile" />
|
||||
</root>
|
||||
</log4net>
|
||||
4
Common/MyLog4Net/packages.config
Normal file
4
Common/MyLog4Net/packages.config
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="log4net" version="2.0.14" targetFramework="net461" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user