示例#1
0
        /// <inheritdoc />
        public override bool Execute()
        {
            var funcLogManager = new FuncLogManager(type => new WrappingFullLogger(new WrappingPrefixLogger(new MsBuildLogger(Log, LogLevel.Debug), type)));

            Locator.CurrentMutable.RegisterConstant(funcLogManager, typeof(ILogManager));

            if (string.IsNullOrWhiteSpace(OutputFile))
            {
                Log.LogError($"{nameof(OutputFile)} is not set");
                return(false);
            }

            if (string.IsNullOrWhiteSpace(TargetFramework))
            {
                Log.LogError($"{nameof(TargetFramework)} is not set");
                return(false);
            }

            using (var writer = new StreamWriter(Path.Combine(OutputFile)))
            {
                ObservablesForEventGenerator.WriteHeader(writer, TargetFramework).ConfigureAwait(false).GetAwaiter().GetResult();

                try
                {
                    ObservablesForEventGenerator.ExtractEventsFromTargetFramework(writer, TargetFramework.ToFrameworks()).GetAwaiter().GetResult();
                }
                catch (Exception ex)
                {
                    this.Log().Error(ex);
                    return(false);
                }
            }

            return(true);
        }
示例#2
0
        public static void UseLog4Net()
        {
            var funcLogManager = new FuncLogManager(type =>
            {
                var actualLogger = log4net.LogManager.GetLogger(type.ToString());
                return new Log4NetSplatLogger(actualLogger);
            });

            Locator.CurrentMutable.RegisterConstant(funcLogManager, typeof(ILogManager));
        }
        /// <summary>
        /// Simple helper to initialize Exceptionless within Splat with the Wrapping Full Logger.
        /// </summary>
        /// <remarks>
        /// You should configure Exceptionless prior to calling this method.
        /// </remarks>
        /// <param name="instance">
        /// An instance of Mutable Dependency Resolver.
        /// </param>
        /// <param name="exceptionlessClient">The exceptionless client instance to use.</param>
        /// <example>
        /// <code>
        /// Locator.CurrentMutable.UseExceptionlessWithWrappingFullLogger(exception);
        /// </code>
        /// </example>
        public static void UseExceptionlessWithWrappingFullLogger(this IMutableDependencyResolver instance, ExceptionlessClient exceptionlessClient)
        {
            var funcLogManager = new FuncLogManager(type =>
            {
                var miniLoggingWrapper = new ExceptionlessSplatLogger(type, exceptionlessClient);
                return(new WrappingFullLogger(miniLoggingWrapper));
            });

            instance.RegisterConstant(funcLogManager, typeof(ILogManager));
        }
示例#4
0
        /// <summary>
        /// Simple helper to initialize Serilog within Splat with the Wrapping Full Logger.
        /// </summary>
        /// <remarks>
        /// You should configure Serilog prior to calling this method.
        /// </remarks>
        /// <param name="instance">An instance of Mutable Dependency Resolver.</param>
        /// <example>
        /// <code>
        /// Locator.CurrentMutable.UseSerilogWithWrappingFullLogger();
        /// </code>
        /// </example>
        public static void UseSerilogFullLogger(this IMutableDependencyResolver instance)
        {
            var funcLogManager = new FuncLogManager(type =>
            {
                var actualLogger = global::Serilog.Log.ForContext(type);
                return(new SerilogFullLogger(actualLogger));
            });

            instance.RegisterConstant(funcLogManager, typeof(ILogManager));
        }
示例#5
0
        public static void UseNLog()
        {
            var funcLogManager = new FuncLogManager(type =>
            {
                var actualLogger = global::NLog.LogManager.GetLogger(type.ToString());
                return new NLogSplatLogger(actualLogger);
            });

            Locator.CurrentMutable.RegisterConstant(funcLogManager, typeof(ILogManager));
        }
示例#6
0
        public static void UseLog4Net()
        {
            var funcLogManager = new FuncLogManager(type =>
            {
                var actualLogger = log4net.LogManager.GetLogger(type.ToString());
                return(new Log4NetSplatLogger(actualLogger));
            });

            Locator.CurrentMutable.RegisterConstant(funcLogManager, typeof(ILogManager));
        }
示例#7
0
        public static void UseNLog()
        {
            var funcLogManager = new FuncLogManager(type =>
            {
                var actualLogger = global::NLog.LogManager.GetLogger(type.ToString());
                return(new NLogSplatLogger(actualLogger));
            });

            Locator.CurrentMutable.RegisterConstant(funcLogManager, typeof(ILogManager));
        }
示例#8
0
        /// <summary>
        /// Simple helper to initialize NLog within Splat with the Wrapping Full Logger.
        /// </summary>
        /// <remarks>
        /// You should configure NLog prior to calling this method.
        /// </remarks>
        /// <param name="instance">
        /// An instance of Mutable Dependency Resolver.
        /// </param>
        /// <example>
        /// <code>
        /// Locator.CurrentMutable.UseNLogWithWrappingFullLogger();
        /// </code>
        /// </example>
        public static void UseNLogWithWrappingFullLogger(this IMutableDependencyResolver instance)
        {
            var funcLogManager = new FuncLogManager(type =>
            {
                var actualLogger       = global::NLog.LogManager.GetLogger(type.ToString());
                var miniLoggingWrapper = new NLogLogger(actualLogger);
                return(new WrappingFullLogger(miniLoggingWrapper));
            });

            instance.RegisterConstant(funcLogManager, typeof(ILogManager));
        }
示例#9
0
        /// <inheritdoc />
        public override void Load(IRegistrator registrar)
        {
            var funcLogManager = new FuncLogManager(type =>
            {
                var actualLogger = Log.ForContext(type);
                return(new SerilogFullLogger(actualLogger));
            });

            registrar.RegisterInstance(Log.Logger);
            registrar.Register <IFullLogger, SerilogFullLogger>(Reuse.Singleton);
            registrar.RegisterInstance(funcLogManager);
        }
        public static IServiceCollection AddSerilog(this IServiceCollection serviceCollection, Func <LoggerConfiguration> factory)
        {
            Log.Logger = factory().CreateLogger();
            var funcLogManager = new FuncLogManager(type =>
            {
                var actualLogger = global::Serilog.Log.ForContext(type);
                return(new SerilogFullLogger(actualLogger));
            });

            serviceCollection.AddSingleton <ILogManager>(funcLogManager);

            return(serviceCollection);
        }
        /// <summary>
        /// Simple helper to initialize Microsoft.Extensions.Logging within Splat with the Wrapping Full Logger.
        /// </summary>
        /// <remarks>
        /// You should configure Microsoft.Extensions.Logging prior to calling this method.
        /// </remarks>
        /// <param name="instance">
        /// An instance of Mutable Dependency Resolver.
        /// </param>
        /// <param name="loggerFactory">
        /// An instance of the Microsoft.Extensions.Logging Logger Factory.
        /// </param>
        /// <example>
        /// <code>
        /// Locator.CurrentMutable.UseMicrosoftExtensionsLoggingWithWrappingFullLogger();
        /// </code>
        /// </example>
        public static void UseMicrosoftExtensionsLoggingWithWrappingFullLogger(
            this IMutableDependencyResolver instance,
            ILoggerFactory loggerFactory)
        {
            var funcLogManager = new FuncLogManager(type =>
            {
                var actualLogger       = loggerFactory.CreateLogger(type.ToString());
                var miniLoggingWrapper = new MicrosoftExtensionsLoggingLogger(actualLogger);
                return(new WrappingFullLogger(miniLoggingWrapper));
            });

            instance.RegisterConstant(funcLogManager, typeof(ILogManager));
        }
示例#12
0
        /// <inheritdoc />
        public override bool Execute()
        {
            var lockFile       = OutputFile + ".lock";
            var funcLogManager = new FuncLogManager(type => new WrappingFullLogger(new WrappingPrefixLogger(new MsBuildLogger(Log, LogLevel.Debug), type)));

            Locator.CurrentMutable.RegisterConstant(funcLogManager, typeof(ILogManager));

            if (string.IsNullOrWhiteSpace(OutputFile))
            {
                Log.LogError($"{nameof(OutputFile)} is not set");
                return(false);
            }

            var nugetFrameworks = GetTargetFrameworks();

            if (nugetFrameworks == null)
            {
                Log.LogError("Neither TargetFramework nor ProjectTypeGuids have been correctly set.");
                return(false);
            }

            var packages = GetPackages();

            var lockPackages = ReadPackages(lockFile);

            if (lockPackages != null && lockPackages.Count == packages.Count && lockPackages.All(packages.Contains))
            {
                return(true);
            }

            using (var writer = new StreamWriter(Path.Combine(OutputFile), false, Encoding.UTF8))
            {
                ObservablesForEventGenerator.WriteHeader(writer, packages).ConfigureAwait(false).GetAwaiter().GetResult();

                try
                {
                    ObservablesForEventGenerator.ExtractEventsFromNuGetPackages(writer, packages, nugetFrameworks).GetAwaiter().GetResult();
                }
                catch (Exception ex)
                {
                    this.Log().Error(ex);
                    return(false);
                }
            }

            WritePackages(packages, lockFile);

            return(true);
        }
        public static void UseExceptionless()
        {
            var funcLogManager = new FuncLogManager(type => new ExceptionlessSplatLogger(type));

            Locator.CurrentMutable.RegisterConstant(funcLogManager, typeof(ILogManager));
        }
示例#14
0
        /// <summary>
        /// Registers Serilog as the Splat logger.
        /// </summary>
        /// <param name="logger">The Serilog logger.</param>
        public static void Register(global::Serilog.ILogger logger)
        {
            var logManager = new FuncLogManager(t => new SerilogLogger(logger.ForContext(t)));

            Splat.Locator.CurrentMutable.RegisterConstant(logManager, typeof(Splat.ILogManager));
        }
        /// <summary>
        /// Simple helper to initialize Log4Net within Splat with the Wrapping Full Logger.
        /// </summary>
        /// <remarks>
        /// You should configure Log4Net prior to calling this method.
        /// </remarks>
        /// <param name="instance">
        /// An instance of Mutable Dependency Resolver.
        /// </param>
        /// <example>
        /// <code>
        /// Locator.CurrentMutable.UseLog4NetWithWrappingFullLogger();
        /// </code>
        /// </example>
        public static void UseLog4NetWithWrappingFullLogger(this IMutableDependencyResolver instance)
        {
            var funcLogManager = new FuncLogManager(type => new WrappingFullLogger(new Log4NetLogger(LogResolver.Resolve(type))));

            instance.RegisterConstant(funcLogManager, typeof(ILogManager));
        }
        public static void UseExceptionless()
        {
            var funcLogManager = new FuncLogManager(type => new ExceptionlessSplatLogger(type));

            Locator.CurrentMutable.RegisterConstant(funcLogManager, typeof(ILogManager));
        }
示例#17
0
        public static async Task <int> Main(string[] args)
        {
            // allow app to be debugged in visual studio.
            if (args.Length == 0 && Debugger.IsAttached)
            {
                args = "generate-platform --platforms=uwp --output-path=test.txt".Split(' ');
            }

            var funcLogManager = new FuncLogManager(type => new WrappingFullLogger(new WrappingPrefixLogger(new ConsoleLogger(), type)));

            Locator.CurrentMutable.RegisterConstant(funcLogManager, typeof(ILogManager));

            var parserResult = new Parser(parserSettings => parserSettings.CaseInsensitiveEnumValues = true)
                               .ParseArguments <CustomAssembliesCommandLineOptions, PlatformCommandLineOptions>(args);

            var result = await parserResult.MapResult(
                async (PlatformCommandLineOptions options) =>
            {
                try
                {
                    var referenceAssembliesLocation = !string.IsNullOrWhiteSpace(options.ReferenceAssemblies)
                            ? options.ReferenceAssemblies !
                            : ReferenceLocator.GetReferenceLocation();

                    if (string.IsNullOrWhiteSpace(options.OutputPath))
                    {
                        throw new Exception("Invalid output path for the event generation.");
                    }

                    if (string.IsNullOrWhiteSpace(options.OutputPrefix))
                    {
                        throw new Exception("Invalid output prefix for the event generation.");
                    }

                    if (options.Platforms == null)
                    {
                        throw new Exception("Invalid platforms for the event generation.");
                    }

                    await ObservablesForEventGenerator.ExtractEventsFromPlatforms(options.OutputPath !, options.OutputPrefix !, ".cs", referenceAssembliesLocation, options.Platforms).ConfigureAwait(false);

                    return(ExitCode.Success);
                }
                catch (Exception ex)
                {
                    LogHost.Default.Fatal(ex);
                    return(ExitCode.Error);
                }
            },
                async (CustomAssembliesCommandLineOptions options) =>
            {
                try
                {
                    using (var writer = new StreamWriter(Path.Combine(options.OutputPath, options.OutputPrefix + ".cs")))
                    {
                        if (options.Assemblies == null)
                        {
                            throw new Exception("Invalid specified assemblies for observable generation.");
                        }

                        if (options.SearchDirectories == null)
                        {
                            throw new Exception("Invalid search directories specified for observable generation.");
                        }

                        if (string.IsNullOrWhiteSpace(options.TargetFramework))
                        {
                            throw new Exception("Invalid target framework for the event generation.");
                        }

                        await ObservablesForEventGenerator.WriteHeader(writer, options.Assemblies !).ConfigureAwait(false);

                        await ObservablesForEventGenerator.ExtractEventsFromAssemblies(writer, options.Assemblies !, options.SearchDirectories !, options.TargetFramework !).ConfigureAwait(false);
                    }

                    return(ExitCode.Success);
                }
                catch (Exception ex)
                {
                    LogHost.Default.Fatal(ex);
                    return(ExitCode.Error);
                }
            },
                async (NugetCommandLineOptions options) =>
            {
                try
                {
                    using (var writer = new StreamWriter(Path.Combine(options.OutputPath, options.OutputPrefix + ".cs")))
                    {
                        if (string.IsNullOrWhiteSpace(options.TargetFramework))
                        {
                            throw new Exception("Invalid target framework for the event generation.");
                        }

                        var packageIdentity = new[] { new LibraryRange(options.NugetPackageName, VersionRange.Parse(options.NugetVersion), LibraryDependencyTarget.Package) };
                        var nugetFramework  = options.TargetFramework !.ToFrameworks();
                        await ObservablesForEventGenerator.WriteHeader(writer, packageIdentity).ConfigureAwait(false);
                        await ObservablesForEventGenerator.ExtractEventsFromNuGetPackages(writer, packageIdentity, nugetFramework, options.PackageFolder).ConfigureAwait(false);
                    }

                    return(ExitCode.Success);
                }
                catch (Exception ex)
                {
                    LogHost.Default.Fatal(ex);
                    return(ExitCode.Error);
                }
            },
                _ =>
            {
                System.Console.WriteLine(HelpText.AutoBuild(parserResult));
                return(Task.FromResult(ExitCode.Error));
            }).ConfigureAwait(false);

            return((int)result);
        }