Compare commits

..

No commits in common. "f2cdfc86b7293e039433952f7772e380474d0ff0" and "613b11e88cd79832d07838cdbc0259ae07cdb389" have entirely different histories.

8 changed files with 22 additions and 80 deletions

1
.gitignore vendored
View File

@ -18,7 +18,6 @@ nuget/
.idea/
.editorconfig
*.user
*.DotSettings
#backups
.old*/

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<!--package info-->
<PackageId>DTLib.Logging.Microsoft</PackageId>
<Version>1.1.1</Version>
<Version>1.1.0</Version>
<Authors>Timerix</Authors>
<Description>DTLib logger wrapper with dependency injection</Description>
<RepositoryType>GIT</RepositoryType>
@ -28,6 +28,6 @@
<ProjectReference Include="..\DTLib\DTLib.csproj" />
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)' != 'Debug' ">
<PackageReference Include="DTLib" Version="1.6.*" />
<PackageReference Include="DTLib" Version="1.4.*" />
</ItemGroup>
</Project>

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<!--package info-->
<PackageId>DTLib</PackageId>
<Version>1.6.1</Version>
<Version>1.6.0</Version>
<Authors>Timerix</Authors>
<Description>Library for all my C# projects</Description>
<RepositoryType>GIT</RepositoryType>

View File

@ -0,0 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=console/@EntryIndexedValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=logging_005Cloggers/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -2,16 +2,23 @@ namespace DTLib.Logging;
public class DefaultLogFormat : ILogFormat
{
public bool PrintTimeStamp { get; set; } = true;
public bool PrintContext { get; set; } = true;
public bool PrintSeverity { get; set; } = true;
public string TimeStampFormat { get; set; } = MyTimeFormat.ForText;
public bool PrintTimeStamp { get; set; }
public bool PrintContext { get; set; }
public bool PrintSeverity { get; set; }
public DefaultLogFormat(bool printTimeStamp = true, bool printContext = true, bool printSeverity = true)
{
PrintTimeStamp = printTimeStamp;
PrintContext = printContext;
PrintSeverity = printSeverity;
}
public string CreateMessage(string context, LogSeverity severity, object message)
{
var sb = new StringBuilder();
if (PrintTimeStamp)
sb.Append('[').Append(DateTime.Now.ToString(TimeStampFormat)).Append(']');
sb.Append('[').Append(DateTime.Now.ToString(MyTimeFormat.ForText)).Append(']');
if (PrintContext && PrintSeverity)
sb.Append('[').Append(context).Append('/').Append(severity.ToString()).Append(']');
else if(PrintContext)

View File

@ -2,5 +2,9 @@ namespace DTLib.Logging;
public interface ILogFormat
{
bool PrintTimeStamp { get; set; }
bool PrintContext { get; set; }
bool PrintSeverity { get; set; }
string CreateMessage(string context, LogSeverity severity, object message);
}

View File

@ -4,6 +4,4 @@ public static class MyTimeFormat
{
public const string ForFileNames="yyyy.MM.dd_HH-mm-ss_zz";
public const string ForText="yyyy.MM.dd HH:mm:ss zz";
public const string TimeOnly="HH:mm:ss";
public const string DateOnly="yyyy.MM.dd";
}

View File

@ -1,69 +0,0 @@
using System.IO;
using File = System.IO.File;
namespace DTLib;
/// <summary>
/// Stream wrapper for some operations over data chunks.
/// You can add multiple transform operations.
/// <example><code>
/// using var pipe = new TransformStream(File.OpenRead("encrypted"))
/// .AddTransform(ReportProgress)
/// .AddTransform(Decrypt);
/// using var o = File.OpenWrite("decrypted");
/// pipe.CopyTo(o);
/// </code></example>
/// </summary>
public class TransformStream : Stream
{
private readonly Stream _inputStream;
public delegate void TransformFuncDelegate(byte[] buffer, int offset, int count);
private List<TransformFuncDelegate> _transformFunctions = new();
public TransformStream(Stream inputStream)
{
_inputStream = inputStream;
}
public TransformStream AddTransform(TransformFuncDelegate f)
{
_transformFunctions.Add(f);
return this;
}
public TransformStream AddTransforms(IEnumerable<TransformFuncDelegate> f)
{
_transformFunctions.AddRange(f);
return this;
}
public override bool CanRead => _inputStream.CanRead;
public override bool CanSeek => _inputStream.CanSeek;
public override bool CanWrite => false;
public override long Length => _inputStream.Length;
public override long Position { get => _inputStream.Position; set => _inputStream.Position = value; }
public override int Read(byte[] buffer, int offset, int count)
{
int read = _inputStream.Read(buffer, offset, count);
if(read > 0)
{
for (int i = 0; i < _transformFunctions.Count; i++)
{
_transformFunctions[i].Invoke(buffer, offset, read);
}
}
return read;
}
public override void Flush() {}
public override long Seek(long offset, SeekOrigin origin) => _inputStream.Seek(offset, origin);
public override void SetLength(long value) => throw new NotImplementedException();
public override void Write(byte[] buffer, int offset, int count) => throw new NotImplementedException();
public override void Close() => _inputStream.Close();
}