Log出力を追加
This commit is contained in:
parent
2a0e652ec7
commit
022f6d61a1
17
FY2526-SW-PoC-APIRelay/AssemblyInfo.cs
Normal file
17
FY2526-SW-PoC-APIRelay/AssemblyInfo.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// このような SDK スタイルのプロジェクトの場合、以前はこのファイルで定義していたいくつかのアセンブリ属性がビルド時に自動的に追加されて、プロジェクトのプロパティで定義されている値がそれに設定されるようになりました。組み込まれる属性と、このプロセスをカスタマイズする方法の詳細については、次を参照してください:
|
||||
// https://aka.ms/assembly-info-properties
|
||||
|
||||
|
||||
// ComVisible を false に設定すると、このアセンブリ内の型は COM コンポーネントから参照できなくなります。このアセンブリ内の型に COM からアクセスする必要がある場合は、その型の
|
||||
// ComVisible 属性を true に設定してください。
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります。
|
||||
|
||||
[assembly: Guid("150a9971-5bd6-4966-aff1-032f60d28cb0")]
|
||||
|
||||
// log4net設定
|
||||
[assembly: log4net.Config.XmlConfigurator(Watch = true, ConfigFile = "log4net.xml")]
|
||||
@ -8,4 +8,14 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="log4net" Version="3.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="log4net.xml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
35
FY2526-SW-PoC-APIRelay/LogWriter.cs
Normal file
35
FY2526-SW-PoC-APIRelay/LogWriter.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace FY2526_SW_PoC_APIRelay
|
||||
{
|
||||
internal class LogWriter
|
||||
{
|
||||
private static readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod()!.DeclaringType!);
|
||||
|
||||
public enum LogLevel
|
||||
{
|
||||
DEBUG,
|
||||
INFO,
|
||||
ERROR
|
||||
}
|
||||
|
||||
public static void WriteLog(string log, LogLevel logLevel)
|
||||
{
|
||||
#if RELEASE
|
||||
if (logLevel == LogLevel.DEBUG)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
logger.Info(string.Format("{0} [{1}] {2}", DateTime.Now, logLevel.ToString(), log));
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
public static void WriteDebugLog(string log,
|
||||
[System.Runtime.CompilerServices.CallerMemberName] string memberName = "",
|
||||
[System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0)
|
||||
{
|
||||
logger.Info(string.Format("{0} [DEBUG] {1}({2}) {3}", DateTime.Now, memberName, sourceLineNumber, log));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,2 +1,30 @@
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
Console.WriteLine("Hello, World!");
|
||||
namespace FY2526_SW_PoC_APIRelay
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
private enum ResultCode : int
|
||||
{
|
||||
Success = 2000,
|
||||
BadParameter = 4000,
|
||||
FileNotFound = 4004,
|
||||
NotTarget = 4005,
|
||||
Error = 5000,
|
||||
ErrorReadFile = 5001,
|
||||
ErrorCleansing = 5002,
|
||||
}
|
||||
|
||||
/// <summary>メイン関数</summary>
|
||||
/// <param name="args">実行引数</param>
|
||||
[STAThread]
|
||||
static void Main(string[] args)
|
||||
{
|
||||
LogWriter.WriteLog("PretreatmentFile 開始", LogWriter.LogLevel.INFO);
|
||||
|
||||
LogWriter.WriteDebugLog(string.Join(" , ", args));
|
||||
|
||||
System.Console.Write("{0}", (int)ResultCode.Success);
|
||||
|
||||
LogWriter.WriteLog("PretreatmentFile 終了", LogWriter.LogLevel.INFO);
|
||||
}
|
||||
}
|
||||
}
|
||||
16
FY2526-SW-PoC-APIRelay/log4net.xml
Normal file
16
FY2526-SW-PoC-APIRelay/log4net.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<log4net>
|
||||
<appender name="LogToFile" type="log4net.Appender.FileAppender">
|
||||
<param name="File" value=".\FY2526-SW-PoC-APIRelay.log"/>
|
||||
<param name="AppendToFile" value ="true"/>
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
<root>
|
||||
<level value="DEBUG" />
|
||||
<appender-ref ref="LogToFile"/>
|
||||
</root>
|
||||
</log4net>
|
||||
</configuration>
|
||||
Loading…
x
Reference in New Issue
Block a user