Ejemplo n.º 1
0
        internal static string ToFileLogUsing(this LogArguments args, IConfiguration configuration)
        {
            var fileConfiguration = configuration as IFormatConfiguration;

            return(args.ToFormatedString(
                       fileConfiguration.FormatProvider,
                       fileConfiguration.Format
                       ));
        }
Ejemplo n.º 2
0
 private static string ToFormatedString(this LogArguments args, IFormatProvider formatProvider, string format) =>
 string.Format(
     formatProvider,
     format,
     args.Level.ToString(),
     DateTime.Now,
     args.ClassName,
     args.MethodName,
     args.Message,
     args.Exception
     ).Trim();
Ejemplo n.º 3
0
 internal static Log ToDatabaseLogUsing(this LogArguments args, IConfiguration configuration) =>
 new Log
 {
     Id        = $"{Guid.NewGuid()}",
     Level     = configuration.ShowLevel.Equals(Yes) ? args.Level.ToString() : null,
     Message   = args.Message,
     Date      = GetFormattedDateFrom(configuration.DateTypeFormat),
     Class     = Path.GetFileNameWithoutExtension(args.ClassName),
     Method    = args.MethodName,
     Exception = args.Exception?.ToString() ?? null
 };
Ejemplo n.º 4
0
        private bool ShouldAdd(LogArguments logArguments, Func <LogArguments, IConfiguration, TLog> toLog)
        {
            if (!logArguments.IsLevelAllowed(configuration.Level))
            {
                return(false);
            }

            var key = $"{DateTime.Now.ToString(AsKey)}-{Guid.NewGuid()}";
            var log = toLog(logArguments, configuration);

            lock (padlock)
                logs.Add(key, log);

            return(true);
        }
Ejemplo n.º 5
0
        public void Write(
            LogArguments logArguments,
            Func <LogArguments, IConfiguration, TLog> toLog,
            Func <KeyValuePair <string, TLog>, TLog> selector)
        {
            if (!ShouldAdd(logArguments, toLog))
            {
                return;
            }

            if (IsUnderThreshold())
            {
                return;
            }

            Write(selector);
        }
Ejemplo n.º 6
0
        public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log, ExecutionContext finCtx)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            LogArguments testArg = new LogArguments(log, LoggerApp.ThisApp, finCtx.InvocationId.ToString(), finCtx.FunctionName.ToString());

            FinLogger.Log("Test Error", LoggerLevel.Error, testArg);
            FinLogger.Log("Test Information ", LoggerLevel.Info, testArg);
            FinLogger.Log("Test Success", LoggerLevel.Success, testArg);
            FinLogger.Log("Test Trace", LoggerLevel.Trace, testArg);

            string name = req.Query["name"];

            string  requestBody = new StreamReader(req.Body).ReadToEnd();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);

            name = name ?? data?.name;

            return(name != null
                ? (ActionResult) new OkObjectResult($"Hello, {name}")
                : new BadRequestObjectResult("Please pass a name on the query string or in the request body"));
        }
Ejemplo n.º 7
0
 private void WriteToConsole(LogArguments logArguments) => logBuffer
 .Write(
     logArguments,
     (logArguments, configuration) => logArguments.ToConsoleLogUsing(configuration),
     kv => kv.Value
     );
Ejemplo n.º 8
0
 private void WriteToFile(LogArguments logArguments) => logBuffer
 .Write(
     logArguments,
     (logArguments, configuration) => logArguments.ToFileLogUsing(configuration),
     kv => $"{kv.Value}{Environment.NewLine}"
     );
 private void WriteToConsole(LogArguments logArguments) => logBuffer
 .Check(logArguments.IsLevelAllowed(configuration.Level))
 ?.Add(logArguments.ToStringLogUsing(configuration))
 .Validate(configuration.BufferSize)
 ?.Write(ConsoleBulkWriter.ToConsole, kv => kv.Value);
Ejemplo n.º 10
0
 private void WriteToFile(LogArguments logArguments) => logBuffer
 .Check(logArguments.IsLevelAllowed(configuration.Level))
 ?.Add(logArguments.ToStringLogUsing(configuration))
 .Validate(configuration.BufferSize)
 ?.Write(FileBulkWriter.ToFileAsync, kv => $"{kv.Value}{Environment.NewLine}");
 private void WriteToDatabase(LogArguments logArguments) => logBuffer
 .Check(logArguments.IsLevelAllowed(configuration.Level))
 ?.Add(logArguments.ToDatabaseLogUsing(configuration))
 .Validate(configuration.BufferSize)
 ?.Write(DatabaseBulkWriter.ToDatabaseAsync, kv => kv.Value);
Ejemplo n.º 12
0
 internal static bool IsLevelAllowed(this LogArguments args, Level level) =>
 level <= args.Level;