Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for getting a zip file IStorageFile directly and a cleanu…

…p mechanism.
  • Loading branch information...
commit 8e9a1e7f7967604b0a6c3be55b1424a9cd73ab11 1 parent f5f1df0
@onovotny onovotny authored
Showing with 228 additions and 120 deletions.
  1. +23 −9 MetroLog.NetCore.Tests/FileSnapshotTests.cs
  2. +4 −2 MetroLog.NetCore/GlobalCrashHandler.cs
  3. +14 −0 MetroLog.NetCore/IWinRTLogManager.cs
  4. +42 −0 MetroLog.NetCore/LogManager.cs
  5. +16 −0 MetroLog.NetCore/LogManagerFactory.cs
  6. +4 −1 MetroLog.NetCore/MetroLog.NetCore.csproj
  7. +0 −21 MetroLog.NetCore/StorageFilePackager.cs
  8. +15 −2 MetroLog.NetCore/WinRTFileTarget.cs
  9. +4 −2 MetroLog.NetCore/XamlExtensionMethods.cs
  10. +4 −1 MetroLog.NetCore/ZipFile.cs
  11. +1 −1  MetroLog.Tests/Tests/BrokenTargetTests.cs
  12. +4 −4 MetroLog.Tests/Tests/FileNamingParametersTests.cs
  13. +19 −19 MetroLog.Tests/Tests/LevelTests.cs
  14. +3 −3 MetroLog.Tests/Tests/LogManagerFactoryTests.cs
  15. +7 −7 MetroLog.Tests/Tests/LogManagerTests.cs
  16. +6 −21 MetroLog.WinRT/Logger.cs
  17. +1 −1  MetroLog.nuspec
  18. +2 −0  MetroLog.sln
  19. +13 −0 MetroLog/ILogManagerFactory.cs
  20. +1 −1  MetroLog/Internal/IAdapterResolver.cs
  21. +2 −2 MetroLog/Internal/LogManager.cs
  22. +3 −2 MetroLog/Internal/PlatformAdapter.cs
  23. +6 −4 MetroLog/Internal/ProbingAdapterResolver.cs
  24. +1 −1  MetroLog/InternalLogger.cs
  25. +1 −1  MetroLog/Layouts/FileSnapshotLayout.cs
  26. +1 −1  MetroLog/Layouts/SingleLineLayout.cs
  27. +1 −1  MetroLog/LogEventInfo.cs
  28. +7 −1 MetroLog/LogManagerFactory.cs
  29. +1 −0  MetroLog/MetroLog.csproj
  30. +10 −10 MetroLog/Properties/AssemblyInfo.cs
  31. +11 −0 MetroLog/Targets/FileTargetBase.cs
  32. +0 −1  Win8Sample/LogSamplePage.xaml.cs
  33. +1 −1  typescript/MetroLog.WinRT.d.ts
View
32 MetroLog.NetCore.Tests/FileSnapshotTests.cs
@@ -1,10 +1,13 @@
-using System;
+extern alias pcl;
+
+using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using MetroLog.Internal;
using MetroLog.Targets;
using Windows.Storage;
using Xunit;
@@ -39,21 +42,32 @@ public class FileSnapshotTargetTests
[Fact]
public async Task TestGetZipFile()
{
- var target = new FileSnapshotTarget();
+ var manager = pcl::MetroLog.LogManagerFactory.CreateLogManager() as IWinRTLogManager;
+
+ var logger = (ILoggerAsync)manager.GetLogger("test");
+
// send through a log entry...
- var op = await target.WriteAsync(new LogWriteContext(),
- new LogEventInfo(LogLevel.Fatal, "TestLogger", "Testing file write...", new InvalidOperationException("An exception message...")));
+ var op = await logger.FatalAsync("Testing file write...", new InvalidOperationException("An exception message..."));
- var folder = await FileSnapshotTarget.EnsureInitializedAsync();
+ var file = await manager.GetCompressedLogFile();
+
+ Assert.True(file.Name.EndsWith(".zip"));
- var str = await target.GetCompressedLogs();
+ var target = manager.DefaultConfiguration.GetTargets().OfType<FileTargetBase>().First();
- var file = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("logs.zip", CreationCollisionOption.ReplaceExisting);
+ await target.ForceCleanupAsync();
- using (var stream = (await file.OpenAsync(FileAccessMode.ReadWrite)).AsStream())
+ var exceptionThrow = false;
+ try
{
- await str.CopyToAsync(stream);
+ var str = await file.OpenReadAsync();
}
+ catch (FileNotFoundException)
+ {
+ exceptionThrow = true;
+ }
+
+ Assert.True(exceptionThrow);
}
}
}
View
6 MetroLog.NetCore/GlobalCrashHandler.cs
@@ -1,4 +1,6 @@
-using System;
+extern alias pcl;
+
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -23,7 +25,7 @@ public static void Configure()
e.Handled = true;
// go...
- var log = (ILoggerAsync)LogManagerFactory.DefaultLogManager.GetLogger<Application>();
+ var log = (ILoggerAsync)pcl::MetroLog.LogManagerFactory.DefaultLogManager.GetLogger<Application>();
await log.FatalAsync("The application crashed: " + e.Message, e.Exception);
// if we're aborting, fake a suspend to flush the targets...
View
14 MetroLog.NetCore/IWinRTLogManager.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Windows.Storage;
+
+namespace MetroLog
+{
+ public interface IWinRTLogManager : ILogManager
+ {
+ Task<IStorageFile> GetCompressedLogFile();
+ }
+}
View
42 MetroLog.NetCore/LogManager.cs
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MetroLog.Internal;
+using Windows.Storage;
+
+namespace MetroLog
+{
+ class LogManager : LogManagerBase, IWinRTLogManager
+ {
+ public LogManager(LoggingConfiguration configuration) : base(configuration)
+ {
+ }
+
+ public async Task<IStorageFile> GetCompressedLogFile()
+ {
+ var stream = await GetCompressedLogs();
+
+ if (stream != null)
+ {
+ // create a temp file
+ var file = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(
+ string.Format("Log - {0}.zip", DateTime.UtcNow.ToString("yyyy-MM-dd HHmmss", CultureInfo.InvariantCulture)), CreationCollisionOption.ReplaceExisting);
+
+ using (var ras = (await file.OpenAsync(FileAccessMode.ReadWrite)).AsStreamForWrite())
+ {
+ await stream.CopyToAsync(ras);
+ }
+
+ stream.Dispose();
+
+ return file;
+ }
+
+ return null;
+ }
+ }
+}
View
16 MetroLog.NetCore/LogManagerFactory.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MetroLog
+{
+ class LogManagerFactory : ILogManagerFactory
+ {
+ public ILogManager Create(LoggingConfiguration configuration)
+ {
+ return new LogManager(configuration);
+ }
+ }
+}
View
5 MetroLog.NetCore/MetroLog.NetCore.csproj
@@ -105,6 +105,7 @@
<ProjectReference Include="..\MetroLog\MetroLog.csproj">
<Project>{65e2062e-aac2-4054-aae6-d6764040c769}</Project>
<Name>MetroLog</Name>
+ <Aliases>global, pcl</Aliases>
</ProjectReference>
</ItemGroup>
<ItemGroup>
@@ -114,12 +115,14 @@
<Compile Include="FileSnapshotTarget.cs" />
<Compile Include="FileNamingMode.cs" />
<Compile Include="FileStreamingTarget.cs" />
+ <Compile Include="IWinRTLogManager.cs" />
<Compile Include="LoggingEnvironment.cs" />
<Compile Include="LogConfigurator.cs" />
<Compile Include="GlobalCrashHandler.cs" />
+ <Compile Include="LogManager.cs" />
+ <Compile Include="LogManagerFactory.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="LazyFlushManager.cs" />
- <Compile Include="StorageFilePackager.cs" />
<Compile Include="WinRTFileTarget.cs" />
<Compile Include="XamlApplicationState.cs" />
<Compile Include="XamlExtensionMethods.cs" />
View
21 MetroLog.NetCore/StorageFilePackager.cs
@@ -1,21 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Windows.Storage;
-
-namespace MetroLog.Packaging
-{
- /// <summary>
- /// Describes a class that can package up events for transmission.
- /// </summary>
- public class StorageFilePackager
- {
- public StorageFilePackager()
- {
- }
-
- }
-}
View
17 MetroLog.NetCore/WinRTFileTarget.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
@@ -10,6 +11,7 @@
using MetroLog.Layouts;
using MetroLog.Targets;
using Windows.Storage;
+using Windows.Storage.Search;
namespace MetroLog
{
@@ -43,8 +45,7 @@ protected WinRTFileTarget(Layout layout) : base(layout)
return ms;
}
-
-
+
protected override Task EnsureInitialized()
{
return EnsureInitializedAsync();
@@ -60,6 +61,18 @@ protected override Task EnsureInitialized()
toDelete.Add(file);
}
+
+ var qo = new QueryOptions(CommonFileQuery.DefaultQuery, new [] {".zip"})
+ {
+ FolderDepth = FolderDepth.Shallow,
+ UserSearchFilter = "System.FileName:~<\"Log -\""
+ };
+
+ var query = ApplicationData.Current.TemporaryFolder.CreateFileQueryWithOptions(qo);
+
+ var oldLogs = await query.GetFilesAsync();
+ toDelete.AddRange(oldLogs);
+
// walk...
foreach (var file in toDelete)
{
View
6 MetroLog.NetCore/XamlExtensionMethods.cs
@@ -1,4 +1,6 @@
-using System;
+extern alias pcl;
+
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -20,7 +22,7 @@ public static class XamlExtensionMethods
/// <returns></returns>
public static ILogger GetLogger(this UserControl control, LoggingConfiguration config = null)
{
- return LogManagerFactory.DefaultLogManager.GetLogger(control.GetType(), config);
+ return pcl::MetroLog.LogManagerFactory.DefaultLogManager.GetLogger(control.GetType(), config);
}
}
}
View
5 MetroLog.NetCore/ZipFile.cs
@@ -99,7 +99,10 @@ public static Task<ZipArchive> OpenRead(Stream archive)
using (Stream stream = (await sourceFile.OpenReadAsync()).AsStream())
{
ZipArchiveEntry zipArchiveEntry = compressionLevel.HasValue ? destination.CreateEntry(entryName, compressionLevel.Value) : destination.CreateEntry(entryName);
- DateTime dateTime = sourceFile.DateCreated.UtcDateTime; //File.GetLastWriteTime(sourceFileName);
+
+ var props = await sourceFile.GetBasicPropertiesAsync();
+
+ DateTime dateTime = props.DateModified.UtcDateTime;
if (dateTime.Year < 1980 || dateTime.Year > 2107)
dateTime = new DateTime(1980, 1, 1, 0, 0, 0);
zipArchiveEntry.LastWriteTime = (DateTimeOffset)dateTime;
View
2  MetroLog.Tests/Tests/BrokenTargetTests.cs
@@ -20,7 +20,7 @@ public class BrokenTargetTests
config.AddTarget(LogLevel.Trace, LogLevel.Fatal, new BrokenTarget());
config.AddTarget(LogLevel.Trace, LogLevel.Fatal, testTarget);
- var target = new LogManager(config);
+ var target = new LogManagerBase(config);
// this should ignore errors in the broken target and flip down to the working target...
var logger = (Logger)target.GetLogger("Foobar");
View
8 MetroLog.Tests/Tests/FileNamingParametersTests.cs
@@ -113,7 +113,7 @@ public void TestTimestampDate()
// check...
var filename = naming.GetFilename(new LogWriteContext(), info);
- Assert.Equal(string.Format("Log - {0}.log", LogManager.GetDateTime().ToString("yyyyMMdd")), filename);
+ Assert.Equal(string.Format("Log - {0}.log", LogManagerBase.GetDateTime().ToString("yyyyMMdd")), filename);
}
[Fact]
@@ -133,7 +133,7 @@ public void TestTimestampTime()
// check...
var filename = naming.GetFilename(new LogWriteContext(), info);
- Assert.Equal(string.Format("Log - {0}.log", LogManager.GetDateTime().ToString("HHmmss")), filename);
+ Assert.Equal(string.Format("Log - {0}.log", LogManagerBase.GetDateTime().ToString("HHmmss")), filename);
}
[Fact]
@@ -153,7 +153,7 @@ public void TestTimestampBoth()
// check...
var filename = naming.GetFilename(new LogWriteContext(), info);
- Assert.Equal(string.Format("Log - {0}.log", LogManager.GetDateTime().ToString("yyyyMMdd HHmmss")), filename);
+ Assert.Equal(string.Format("Log - {0}.log", LogManagerBase.GetDateTime().ToString("yyyyMMdd HHmmss")), filename);
}
[Fact]
@@ -174,7 +174,7 @@ public void TestEverythingOn()
// check...
var context = new LogWriteContext();
var filename = naming.GetFilename(context, info);
- Assert.Equal(string.Format("Log - INFO - foobar - {0} - {1} - {2}.log", LogManager.GetDateTime().ToString("yyyyMMdd HHmmss"),
+ Assert.Equal(string.Format("Log - INFO - foobar - {0} - {1} - {2}.log", LogManagerBase.GetDateTime().ToString("yyyyMMdd HHmmss"),
context.Environment.SessionId, info.SequenceID), filename);
}
View
38 MetroLog.Tests/Tests/LevelTests.cs
@@ -17,7 +17,7 @@ public class LevelTests
var config = new LoggingConfiguration();
config.AddTarget(min, max, testTarget);
- return Tuple.Create<ILogManager, TestTarget>(new LogManager(config), testTarget);
+ return Tuple.Create<ILogManager, TestTarget>(new LogManagerBase(config), testTarget);
}
[Fact]
@@ -184,7 +184,7 @@ public void TestIsErrorEnabled()
[Fact]
public void TestIsFatalEnabled()
{
- var target = new LogManager(new LoggingConfiguration());
+ var target = new LogManagerBase(new LoggingConfiguration());
// get a logger...
var logger = target.GetLogger("foo");
@@ -201,9 +201,9 @@ public void TestIsFatalEnabled()
//[Fact]
//public void TestIsTraceEnabledForLoggable()
//{
- // LogManager.Reset();
- // LogManager.DefaultConfiguration.ClearTargets();
- // LogManager.DefaultConfiguration.AddTarget(LogLevel.Debug, LogLevel.Fatal, TestTarget.Current);
+ // LogManagerBase.Reset();
+ // LogManagerBase.DefaultConfiguration.ClearTargets();
+ // LogManagerBase.DefaultConfiguration.AddTarget(LogLevel.Debug, LogLevel.Fatal, TestTarget.Current);
// // get a loggable...
// var loggable = new TestLoggable();
@@ -220,9 +220,9 @@ public void TestIsFatalEnabled()
//[Fact]
//public void TestIsDebugEnabledForLoggable()
//{
- // LogManager.Reset();
- // LogManager.DefaultConfiguration.ClearTargets();
- // LogManager.DefaultConfiguration.AddTarget(LogLevel.Info, LogLevel.Fatal, TestTarget.Current);
+ // LogManagerBase.Reset();
+ // LogManagerBase.DefaultConfiguration.ClearTargets();
+ // LogManagerBase.DefaultConfiguration.AddTarget(LogLevel.Info, LogLevel.Fatal, TestTarget.Current);
// // get a loggable...
// var loggable = new TestLoggable();
@@ -239,9 +239,9 @@ public void TestIsFatalEnabled()
//[Fact]
//public void TestIsInfoEnabledForLoggable()
//{
- // LogManager.Reset();
- // LogManager.DefaultConfiguration.ClearTargets();
- // LogManager.DefaultConfiguration.AddTarget(LogLevel.Warn, LogLevel.Fatal, TestTarget.Current);
+ // LogManagerBase.Reset();
+ // LogManagerBase.DefaultConfiguration.ClearTargets();
+ // LogManagerBase.DefaultConfiguration.AddTarget(LogLevel.Warn, LogLevel.Fatal, TestTarget.Current);
// // get a loggable...
// var loggable = new TestLoggable();
@@ -258,9 +258,9 @@ public void TestIsFatalEnabled()
//[Fact]
//public void TestIsWarnEnabledForLoggable()
//{
- // LogManager.Reset();
- // LogManager.DefaultConfiguration.ClearTargets();
- // LogManager.DefaultConfiguration.AddTarget(LogLevel.Error, LogLevel.Fatal, TestTarget.Current);
+ // LogManagerBase.Reset();
+ // LogManagerBase.DefaultConfiguration.ClearTargets();
+ // LogManagerBase.DefaultConfiguration.AddTarget(LogLevel.Error, LogLevel.Fatal, TestTarget.Current);
// // get a loggable...
// var loggable = new TestLoggable();
@@ -277,9 +277,9 @@ public void TestIsFatalEnabled()
//[Fact]
//public void TestIsErrorEnabledForLoggable()
//{
- // LogManager.Reset();
- // LogManager.DefaultConfiguration.ClearTargets();
- // LogManager.DefaultConfiguration.AddTarget(LogLevel.Fatal, TestTarget.Current);
+ // LogManagerBase.Reset();
+ // LogManagerBase.DefaultConfiguration.ClearTargets();
+ // LogManagerBase.DefaultConfiguration.AddTarget(LogLevel.Fatal, TestTarget.Current);
@@ -298,8 +298,8 @@ public void TestIsFatalEnabled()
//[Fact]
//public void TestIsFatalEnabledForLoggable()
//{
- // LogManager.Reset();
- // LogManager.DefaultConfiguration.ClearTargets();
+ // LogManagerBase.Reset();
+ // LogManagerBase.DefaultConfiguration.ClearTargets();
// // get a loggable...
// var loggable = new TestLoggable();
View
6 MetroLog.Tests/Tests/LogManagerFactoryTests.cs
@@ -7,7 +7,7 @@
namespace MetroLog.Tests.Tests
{
- public class LogManagerFactoryTests
+ public class LogManagerBaseFactoryTests
{
// [Fact]
public void InitalizeCallsSetDefault()
@@ -15,9 +15,9 @@ public void InitalizeCallsSetDefault()
bool wasCalled = false;
// using (ShimsContext.Create())
//{
- // ShimLogManagerFactoryBase.SetDefaultLogManagerILogManager = lm => wasCalled = true;
+ // ShimLogManagerBaseFactoryBase.SetDefaultLogManagerBaseILogManager = lm => wasCalled = true;
- //LogManagerFactory.Initialize();
+ //LogManagerBaseFactory.Initialize();
//}
Assert.True(wasCalled);
View
14 MetroLog.Tests/Tests/LogManagerTests.cs
@@ -9,12 +9,12 @@
namespace MetroLog.Tests
{
- public class LogManagerTests
+ public class LogManagerBaseTests
{
[Fact]
public void TestGetLogger()
{
- var manager = new LogManager(new LoggingConfiguration());
+ var manager = new LogManagerBase(new LoggingConfiguration());
var logger = manager.GetLogger("Foobar");
Assert.NotNull(logger);
@@ -23,9 +23,9 @@ public void TestGetLogger()
[Fact]
public void TestGetLoggerByType()
{
- var manager = new LogManager(new LoggingConfiguration());
+ var manager = new LogManagerBase(new LoggingConfiguration());
- var logger = manager.GetLogger<LogManagerTests>();
+ var logger = manager.GetLogger<LogManagerBaseTests>();
Assert.NotNull(logger);
}
@@ -34,14 +34,14 @@ public void TestGetLoggerByType()
public void TestLoggerCreated()
{
bool called = false;
- var manager = new LogManager(new LoggingConfiguration());
+ var manager = new LogManagerBase(new LoggingConfiguration());
manager.LoggerCreated += (sender, args) =>
{
called = true;
};
// call...
- var logger = manager.GetLogger<LogManagerTests>();
+ var logger = manager.GetLogger<LogManagerBaseTests>();
// check...
Assert.True(called);
@@ -51,7 +51,7 @@ public void TestLoggerCreated()
public async Task TestGetZipNetFile()
{
- var manager = new LogManager(LogManagerFactory.CreateLibraryDefaultSettings());
+ var manager = new LogManagerBase(LogManagerFactory.CreateLibraryDefaultSettings());
manager.DefaultConfiguration.AddTarget(LogLevel.Trace, LogLevel.Fatal, new StreamingFileTarget());
var logger = (ILoggerAsync)manager.GetLogger("test");
View
27 MetroLog.WinRT/Logger.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
@@ -9,7 +8,6 @@
using MetroLog.Targets;
using Windows.Foundation;
using Windows.Storage;
-using Windows.Storage.Streams;
using IPclLogger = MetroLog.ILogger;
using PclLogLevel = MetroLog.LogLevel;
@@ -18,14 +16,14 @@ namespace MetroLog.WinRT
public sealed class Logger : ILogger
{
private readonly IPclLogger _logger;
- private static readonly Lazy<ILogManager> _logManager;
+ private static readonly Lazy<IWinRTLogManager> _logManager;
public static event EventHandler<string> OnLogMessage;
private static readonly SynchronizationContext _context = SynchronizationContext.Current;
static Logger()
{
- _logManager = new Lazy<ILogManager>(() =>
+ _logManager = new Lazy<IWinRTLogManager>(() =>
{
// Log everything for now
var configuration = new LoggingConfiguration();
@@ -36,30 +34,17 @@ static Logger()
LogManagerFactory.DefaultConfiguration = configuration;
- return LogManagerFactory.DefaultLogManager;
+ return (IWinRTLogManager)LogManagerFactory.DefaultLogManager;
});
}
/// <summary>
- /// Returns a zip file stream of compressed logs
+ /// Returns a zip file of the compressed logs
/// </summary>
/// <returns></returns>
- public static IAsyncOperation<IRandomAccessStream> GetCompressedLogs()
+ public static IAsyncOperation<IStorageFile> GetCompressedLogFile()
{
- return GetCompressedLogsInternal().AsAsyncOperation();
- }
-
- private static async Task<IRandomAccessStream> GetCompressedLogsInternal()
- {
- using (var stream = await _logManager.Value.GetCompressedLogs())
- {
- // Copy to a WinRT buffer
- var dest = new InMemoryRandomAccessStream();
- await stream.CopyToAsync(dest.AsStreamForWrite());
- dest.Seek(0);
-
- return dest;
- }
+ return _logManager.Value.GetCompressedLogFile().AsAsyncOperation();
}
private static void OnLogMessageInternal(string message)
View
2  MetroLog.nuspec
@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MetroLog</id>
- <version>0.7.1</version>
+ <version>0.7.5</version>
<title>MetroLog Lightweight Logging for Portable and WinJS</title>
<authors>Matt Baxter-Reynolds,Oren Novotny</authors>
<owners>onovotny</owners>
View
2  MetroLog.sln
@@ -7,8 +7,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MetroLog.Tests", "MetroLog.
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B59C05D2-3F0D-40CB-8753-7F63D458AF00}"
ProjectSection(SolutionItems) = preProject
+ typescript\MetroLog.WinRT.d.ts = typescript\MetroLog.WinRT.d.ts
README.mdown = README.mdown
SharedAssemblyInfo.cs = SharedAssemblyInfo.cs
+ typescript\winrt.d.ts = typescript\winrt.d.ts
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MetroLog.NetFx", "MetroLog.NetFx\MetroLog.NetFx.csproj", "{B929FFC8-CA0D-43FD-A95B-8E454CCD7133}"
View
13 MetroLog/ILogManagerFactory.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MetroLog
+{
+ public interface ILogManagerFactory
+ {
+ ILogManager Create(LoggingConfiguration configuration);
+ }
+}
View
2  MetroLog/Internal/IAdapterResolver.cs
@@ -8,6 +8,6 @@ namespace MetroLog.Internal
{
internal interface IAdapterResolver
{
- object Resolve(Type type);
+ object Resolve(Type type, object[] args);
}
}
View
4 MetroLog/Internal/LogManager.cs
@@ -8,7 +8,7 @@
namespace MetroLog.Internal
{
- internal class LogManager : ILogManager
+ internal class LogManagerBase : ILogManager
{
public LoggingConfiguration DefaultConfiguration { get; private set; }
@@ -33,7 +33,7 @@ public Task<Stream> GetCompressedLogs()
internal const string DateTimeFormat = "o";
- public LogManager(LoggingConfiguration configuration)
+ public LogManagerBase(LoggingConfiguration configuration)
{
if (configuration == null)
throw new ArgumentNullException("configuration");
View
5 MetroLog/Internal/PlatformAdapter.cs
@@ -12,9 +12,9 @@ internal static class PlatformAdapter
private static readonly string[] KnownPlatformNames = new[] { "NetFx", "NetCore" };
private static IAdapterResolver _resolver = new ProbingAdapterResolver(KnownPlatformNames);
- public static T Resolve<T>(bool throwIfNotFound = true)
+ public static T Resolve<T>(bool throwIfNotFound = true, params object[] args)
{
- T value = (T)_resolver.Resolve(typeof(T));
+ T value = (T)_resolver.Resolve(typeof(T), args);
if (value == null && throwIfNotFound)
throw new PlatformNotSupportedException(Strings.AdapterNotSupported);
@@ -22,6 +22,7 @@ public static T Resolve<T>(bool throwIfNotFound = true)
return value;
}
+
// Unit testing helper
internal static void SetResolver(IAdapterResolver resolver)
{
View
10 MetroLog/Internal/ProbingAdapterResolver.cs
@@ -33,7 +33,7 @@ public ProbingAdapterResolver(Func<AssemblyName, Assembly> assemblyLoader, param
_assemblyLoader = assemblyLoader;
}
- public object Resolve(Type type)
+ public object Resolve(Type type, object[] args)
{
Debug.Assert(type != null);
@@ -43,7 +43,7 @@ public object Resolve(Type type)
if (!_adapters.TryGetValue(type, out instance))
{
Assembly assembly = GetPlatformSpecificAssembly();
- instance = ResolveAdapter(assembly, type);
+ instance = ResolveAdapter(assembly, type, args);
_adapters.Add(type, instance);
}
@@ -51,7 +51,7 @@ public object Resolve(Type type)
}
}
- private static object ResolveAdapter(Assembly assembly, Type interfaceType)
+ private static object ResolveAdapter(Assembly assembly, Type interfaceType, object[] args)
{
string typeName = MakeAdapterTypeName(interfaceType);
@@ -64,7 +64,9 @@ private static object ResolveAdapter(Assembly assembly, Type interfaceType)
// Fallback to looking in this assembly for a default
type = typeof (ProbingAdapterResolver).GetTypeInfo().Assembly.GetType(typeName);
if (type != null)
- return Activator.CreateInstance(type);
+ {
+ return Activator.CreateInstance(type, args);
+ }
return type;
}
View
2  MetroLog/InternalLogger.cs
@@ -109,7 +109,7 @@ public void Log(LogLevel logLevel, string message, Exception ex)
{
string formatted = null;
long sequence = LogEventInfo.GetNextSequenceId();
- string dt = LogManager.GetDateTime().ToString(LogManager.DateTimeFormat);
+ string dt = LogManagerBase.GetDateTime().ToString(LogManagerBase.DateTimeFormat);
string asString = logLevel.ToString().ToUpper();
int thread = Environment.CurrentManagedThreadId;
if (ex != null)
View
2  MetroLog/Layouts/FileSnapshotLayout.cs
@@ -15,7 +15,7 @@ public override string GetFormattedString(LogWriteContext context, LogEventInfo
builder.Append("Sequence: ");
builder.Append(info.SequenceID);
builder.Append("\r\nDate/time: ");
- builder.Append(info.TimeStamp.ToString(LogManager.DateTimeFormat));
+ builder.Append(info.TimeStamp.ToString(LogManagerBase.DateTimeFormat));
builder.Append("\r\nLevel: ");
builder.Append(info.Level.ToString().ToUpper());
builder.Append("\r\nThread: ");
View
2  MetroLog/Layouts/SingleLineLayout.cs
@@ -14,7 +14,7 @@ public override string GetFormattedString(LogWriteContext context, LogEventInfo
StringBuilder builder = new StringBuilder();
builder.Append(info.SequenceID);
builder.Append("|");
- builder.Append(info.TimeStamp.ToString(LogManager.DateTimeFormat));
+ builder.Append(info.TimeStamp.ToString(LogManagerBase.DateTimeFormat));
builder.Append("|");
builder.Append(info.Level.ToString().ToUpper());
builder.Append("|");
View
2  MetroLog/LogEventInfo.cs
@@ -29,7 +29,7 @@ public LogEventInfo(LogLevel level, string logger, string message, Exception ex)
Logger = logger;
Message = message;
Exception = ex;
- TimeStamp = LogManager.GetDateTime();
+ TimeStamp = LogManagerBase.GetDateTime();
SequenceID = GetNextSequenceId();
}
View
8 MetroLog/LogManagerFactory.cs
@@ -32,7 +32,13 @@ public static ILogManager CreateLogManager(LoggingConfiguration config = null)
var cfg = config ?? DefaultConfiguration;
cfg.Freeze();
- var manager = new LogManager(cfg);
+
+ ILogManager manager;
+ var managerFactory = PlatformAdapter.Resolve<ILogManagerFactory>(false);
+ if (managerFactory != null)
+ manager = managerFactory.Create(cfg);
+ else
+ manager = new LogManagerBase(cfg);
_configurator.OnLogManagerCreated(manager);
View
1  MetroLog/MetroLog.csproj
@@ -109,6 +109,7 @@
</Compile>
<Compile Include="ExceptionWrapper.cs" />
<Compile Include="ILogConfigurator.cs" />
+ <Compile Include="ILogManagerFactory.cs" />
<Compile Include="Internal\AsyncLock.cs" />
<Compile Include="Internal\SimpleJson.cs" />
<Compile Include="LogConfigurator.cs" />
View
20 MetroLog/Properties/AssemblyInfo.cs
@@ -11,17 +11,17 @@
[assembly: ComVisible(false)]
//[assembly: SecurityTransparent]
-//[assembly: InternalsVisibleTo("MetroLog.NetCore, PublicKey=00240000048000009400000006020000002400005253413100040000010001002b4b7e56af036d" +
-// "ed95a703d3ffc367837e047f6fbdba8fae1d1295a5c031a108aa452c62f14b7a12766f86a0f94f" +
-// "28dae83980e5b69e97985899ae9299dd6951b0933d13416c564b3997d8ed784208afa2e18f0389" +
-// "9da14d209054ce3002e47e9ae1bd811baa2a20899c5f6c8211b886be9284541d58476fbabc7323" +
-// "90a0f7c9")]
+[assembly: InternalsVisibleTo("MetroLog.NetCore, PublicKey=00240000048000009400000006020000002400005253413100040000010001002b4b7e56af036d" +
+ "ed95a703d3ffc367837e047f6fbdba8fae1d1295a5c031a108aa452c62f14b7a12766f86a0f94f" +
+ "28dae83980e5b69e97985899ae9299dd6951b0933d13416c564b3997d8ed784208afa2e18f0389" +
+ "9da14d209054ce3002e47e9ae1bd811baa2a20899c5f6c8211b886be9284541d58476fbabc7323" +
+ "90a0f7c9")]
-//[assembly: InternalsVisibleTo("MetroLog.NetFx, PublicKey=00240000048000009400000006020000002400005253413100040000010001002b4b7e56af036d" +
-// "ed95a703d3ffc367837e047f6fbdba8fae1d1295a5c031a108aa452c62f14b7a12766f86a0f94f" +
-// "28dae83980e5b69e97985899ae9299dd6951b0933d13416c564b3997d8ed784208afa2e18f0389" +
-// "9da14d209054ce3002e47e9ae1bd811baa2a20899c5f6c8211b886be9284541d58476fbabc7323" +
-// "90a0f7c9")]
+[assembly: InternalsVisibleTo("MetroLog.NetFx, PublicKey=00240000048000009400000006020000002400005253413100040000010001002b4b7e56af036d" +
+ "ed95a703d3ffc367837e047f6fbdba8fae1d1295a5c031a108aa452c62f14b7a12766f86a0f94f" +
+ "28dae83980e5b69e97985899ae9299dd6951b0933d13416c564b3997d8ed784208afa2e18f0389" +
+ "9da14d209054ce3002e47e9ae1bd811baa2a20899c5f6c8211b886be9284541d58476fbabc7323" +
+ "90a0f7c9")]
// mbr - 2012-09-15 - added at the suggestion of @davkean...
[assembly: NeutralResourcesLanguage("en-US")]
View
11 MetroLog/Targets/FileTargetBase.cs
@@ -51,6 +51,17 @@ internal Task<Stream> GetCompressedLogs()
return GetCompressedLogsInternal();
}
+ internal async Task ForceCleanupAsync()
+ {
+ // threshold...
+ var threshold = DateTime.UtcNow.AddDays(0 - RetainDays);
+
+ // walk...
+ var regex = FileNamingParameters.GetRegex();
+
+ await DoCleanup(regex, threshold);
+ }
+
private async Task CheckCleanupAsync()
{
var now = DateTime.UtcNow;
View
1  Win8Sample/LogSamplePage.xaml.cs
@@ -1,5 +1,4 @@
using MetroLog;
-using MetroLog.Packaging;
using MetroLog.Targets;
using System;
using System.Collections.Generic;
View
2  typescript/MetroLog.WinRT.d.ts
@@ -55,7 +55,7 @@ module MetroLog {
export class Logger {
static getLogger(name : string): ILogger;
- static getCompressedLogs(): Windows.Foundation.IAsyncOperation__IRandomAccessStream;
+ static getCompressedLogs(): Windows.Foundation.IAsyncOperation__StorageFile;
static addEventListener(eventName: string, f: Function): void;
static removeEventListener(eventName: string);
Please sign in to comment.
Something went wrong with that request. Please try again.