Append ZeroLevel.Logger

pull/1/head
Ogoun 5 years ago
parent a074f9c02a
commit 0711da45b3

@ -5,10 +5,6 @@
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BaGet.Protocol" Version="0.2.0-preview1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ZeroLevel\ZeroLevel.csproj" />
</ItemGroup>

@ -1,9 +1,4 @@
using BaGet.Protocol;
using NuGet.Versioning;
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System;
using ZeroLevel;
namespace ConfigurationTests

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="useFileLog" value="true"/>
<add key="useConsoleLog" value="true"/>
<add key="port" value="90"/>
</appSettings>
</configuration>

@ -0,0 +1,40 @@
using ZeroLevel.Logger.ProxySample;
using ZeroLevel.Network;
using ZeroLevel.Services.Applications;
namespace ZeroLevel.Logger
{
public class LogService
: BaseZeroService
{
public LogService()
: base()
{
var config = Configuration.Default;
if (config.FirstOrDefault<bool>("useConsoleLog"))
{
Log.AddConsoleLogger(Logging.LogLevel.FullDebug);
}
if (config.FirstOrDefault<bool>("useFileLog"))
{
Log.AddTextFileLogger(new Logging.TextFileLoggerOptions().SetFolderPath("logs"));
}
AutoregisterInboxes(UseHost(config.First<int>("port")));
}
protected override void StartAction()
{
}
protected override void StopAction()
{
}
[ExchangeHandler("log")]
public void LogMessageHandler(ISocketClient client, LogMessage message)
{
Log.Write(message.Level, message.Message);
}
}
}

@ -0,0 +1,15 @@
namespace ZeroLevel.Logger
{
class Program
{
static void Main(string[] args)
{
Bootstrap.Startup<LogService>(args)
.EnableConsoleLog()
.Run()
.WaitWhileStatus(ZeroServiceStatus.Running)
.Stop();
Bootstrap.Shutdown();
}
}
}

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PublishDir>bin\Release\netcoreapp3.1\publish\</PublishDir>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun>False</PublishReadyToRun>
<PublishTrimmed>False</PublishTrimmed>
</PropertyGroup>
</Project>

@ -0,0 +1,24 @@
using ZeroLevel.Logging;
using ZeroLevel.Services.Serialization;
namespace ZeroLevel.Logger.ProxySample
{
public class LogMessage
: IBinarySerializable
{
public LogLevel Level { get; set; }
public string Message { get; set; }
public void Deserialize(IBinaryReader reader)
{
this.Level = (LogLevel)reader.ReadInt32();
this.Message = reader.ReadString();
}
public void Serialize(IBinaryWriter writer)
{
writer.WriteInt32((int)this.Level);
writer.WriteString(this.Message);
}
}
}

@ -0,0 +1,38 @@
using System;
using System.Net;
using ZeroLevel.Logging;
using ZeroLevel.Network;
namespace ZeroLevel.Logger.ProxySample
{
public class LogProxy
: IDisposable
{
private readonly IExchange _exchange;
public LogProxy(IPEndPoint endpoint)
{
_exchange = Bootstrap.CreateExchange();
_exchange.RoutesStorage.Set("log.service", endpoint);
}
public void Dispose()
{
_exchange?.Dispose();
}
public bool SendLog(LogMessage message)
{
try
{
return _exchange.Send("log.service", "log", message);
}
catch (Exception ex)
{
Log.Error(ex, "[LogProxy] SendLog");
return false;
}
}
public bool SendLog(LogLevel level, string message) => SendLog(new LogMessage { Level = level, Message = message });
}
}

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ZeroLevel\ZeroLevel.csproj" />
</ItemGroup>
</Project>

@ -35,6 +35,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfigurationTests", "Confi
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DependencyInjectionTests", "DependencyInjectionTests\DependencyInjectionTests.csproj", "{665B38E3-A5F2-4AD0-946B-209D80C1AA40}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZeroLevel.Logger", "ZeroLevel.Logger\ZeroLevel.Logger.csproj", "{D1C061DB-3565-43C3-B8F3-628DE4908750}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -213,6 +215,18 @@ Global
{665B38E3-A5F2-4AD0-946B-209D80C1AA40}.Release|x64.Build.0 = Release|Any CPU
{665B38E3-A5F2-4AD0-946B-209D80C1AA40}.Release|x86.ActiveCfg = Release|Any CPU
{665B38E3-A5F2-4AD0-946B-209D80C1AA40}.Release|x86.Build.0 = Release|Any CPU
{D1C061DB-3565-43C3-B8F3-628DE4908750}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D1C061DB-3565-43C3-B8F3-628DE4908750}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D1C061DB-3565-43C3-B8F3-628DE4908750}.Debug|x64.ActiveCfg = Debug|Any CPU
{D1C061DB-3565-43C3-B8F3-628DE4908750}.Debug|x64.Build.0 = Debug|Any CPU
{D1C061DB-3565-43C3-B8F3-628DE4908750}.Debug|x86.ActiveCfg = Debug|Any CPU
{D1C061DB-3565-43C3-B8F3-628DE4908750}.Debug|x86.Build.0 = Debug|Any CPU
{D1C061DB-3565-43C3-B8F3-628DE4908750}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D1C061DB-3565-43C3-B8F3-628DE4908750}.Release|Any CPU.Build.0 = Release|Any CPU
{D1C061DB-3565-43C3-B8F3-628DE4908750}.Release|x64.ActiveCfg = Release|Any CPU
{D1C061DB-3565-43C3-B8F3-628DE4908750}.Release|x64.Build.0 = Release|Any CPU
{D1C061DB-3565-43C3-B8F3-628DE4908750}.Release|x86.ActiveCfg = Release|Any CPU
{D1C061DB-3565-43C3-B8F3-628DE4908750}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -87,7 +87,7 @@ namespace ZeroLevel
static Bootstrap()
{
// Tricks for minimize config changes for dependency resolve
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
//AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)

@ -5,12 +5,18 @@ namespace ZeroLevel.Logging
public sealed class DelegateLogger : ILogger
{
private readonly Action<string> _handler;
private readonly Action<LogLevel, string> _handlerFull;
public DelegateLogger(Action<string> handler)
{
_handler = handler ?? throw new ArgumentNullException(nameof(handler));
}
public DelegateLogger(Action<LogLevel, string> handler)
{
_handlerFull = handler ?? throw new ArgumentNullException(nameof(handler));
}
public void Dispose()
{
}
@ -21,11 +27,13 @@ namespace ZeroLevel.Logging
{
if (level == LogLevel.Raw)
{
_handler(message);
_handler?.Invoke(message);
_handlerFull?.Invoke(level, message);
}
else
{
_handler($"[{DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss")} {LogLevelNameMapping.CompactName(level)}] {message}");
_handler?.Invoke($"[{DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss")} {LogLevelNameMapping.CompactName(level)}] {message}");
_handlerFull?.Invoke(level, message);
}
}
catch

@ -21,7 +21,10 @@ namespace ZeroLevel
#endregion Ctor
#region Logging
public static void Write(LogLevel level, string message)
{
_router.Write(level, message);
}
public static void Raw(string line, params object[] args)
{
_router.Write(LogLevel.Raw, FormatMessage(line, args));
@ -139,6 +142,11 @@ namespace ZeroLevel
AddLogger(new DelegateLogger(handler), level);
}
public static void AddDelegateLogger(Action<LogLevel, string> handler, LogLevel level = LogLevel.Standart)
{
AddLogger(new DelegateLogger(handler), level);
}
#endregion Delegate logger
#region Console

Loading…
Cancel
Save

Powered by TurnKey Linux.