NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Schwab.Rps.DigitalFinancialGuide.Management.Bff.Logging.Interfaces;
using Schwab.Rps.DigitalFinancialGuide.Management.Bff.Models;

namespace Schwab.Rps.DigitalFinancialGuide.Management.Bff.Logging
{
/// <summary>
/// wrapper for logging to splunk and rpslog db
/// </summary>
public class SchwabPlanServiceLogger : ISchwabPlanServiceLogger
{
/// <summary>
/// class to log to splunk
/// </summary>
private readonly ISplunkLogging _splunkLogging;
/// <summary>
/// default log level - won't log if loglevel is below default log level
/// </summary>
private readonly LogLevel _defaultLogLevel;
/// <summary>
/// class to log to app audit table in rpslog
/// </summary>
private readonly IAppAuditLogging _appAuditLogging;
/// <summary>
/// class to log to app support table in rpslog
/// </summary>
private readonly IAppSupportLogging _appSupportLogging;

/// <summary>
/// SchwabPlanServiceLogger constructor
/// </summary>
/// <param name="defaultLogLevel">default log level</param>
/// <param name="splunkLogging">logging to splunk</param>
/// <param name="appAuditLogging">logging to app audit</param>
/// <param name="appSupportLogging">logging to app support</param>
public SchwabPlanServiceLogger(string defaultLogLevel, ISplunkLogging splunkLogging, IAppAuditLogging appAuditLogging, IAppSupportLogging appSupportLogging)
{
_splunkLogging = splunkLogging;
_defaultLogLevel = GetLogLevel(defaultLogLevel).Result;
_appAuditLogging = appAuditLogging;
_appSupportLogging = appSupportLogging;
}

/// <summary>
/// log error to splunk and app support
/// </summary>
/// <param name="ex">exception thrown</param>
/// <returns>async task</returns>
public async Task LogError(Exception ex)
{
if (_defaultLogLevel != LogLevel.None)
{
var loggingTasks = new[]
{
//Task.Run(() => _appSupportLogging.LogException(ex)),
Task.Run(() => _splunkLogging.LogException(ex))
};
try
{
await Task.WhenAll(loggingTasks);
}
catch (Exception ex1)
{
Console.WriteLine(ex1.Message);
Console.WriteLine(ex1.StackTrace);
}

}
}

/// <summary>
/// log message to splunk and app audit
/// </summary>
/// <param name="message">message to log</param>
/// <param name="logLevel">log level</param>
/// <returns>async task</returns>
public async Task LogMessage(string message, LogLevel logLevel= LogLevel.Debug)
{
if (_defaultLogLevel != LogLevel.None && logLevel >= _defaultLogLevel)
{
var loggingTasks = new[]
{
Task.Run(() => _splunkLogging.LogMessage(message, logLevel))
};
try
{
await Task.WhenAll(loggingTasks);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}

}
}

/// <summary>
/// log message to splunk and app audit
/// </summary>
/// <param name="message">message to log</param>
/// /// <param name="functionality">functional identifier for the action</param>
/// <param name="logLevel">log level</param>
/// <returns>async task</returns>
public async Task LogSplunkMessage(string message, string functionality, LogLevel logLevel = LogLevel.Debug)
{
if (_defaultLogLevel != LogLevel.None && logLevel >= _defaultLogLevel)
{
try
{
await _splunkLogging.LogMessage(message, logLevel, functionality);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}

/// <summary>
/// log client messages to either splunk and app support or app audit
/// </summary>
/// <param name="loggingEntity">contains data to log</param>
/// <returns>async task</returns>
public async Task LogFrontEndMessage(FrontEndLoggingEntity loggingEntity)
{
Task[] loggingTasks = null;
var logSeverity = GetLogLevel(loggingEntity.LogLevel).Result;

if (logSeverity != LogLevel.None && logSeverity >= _defaultLogLevel)
{
if (logSeverity >= LogLevel.Error)
{
loggingTasks = new[]
{
//Task.Run(() => _appSupportLogging.LogException(loggingEntity.Message, loggingEntity.StackTrace, loggingEntity.Component)),
Task.Run(() => _splunkLogging.LogException(loggingEntity.Message, loggingEntity.StackTrace, loggingEntity.Component))
};
}
else
{
loggingTasks = new[]
{
//Task.Run(() => _appAuditLogging.LogMessage(loggingEntity.Message)),
Task.Run(() => _splunkLogging.LogMessage(loggingEntity.Message))
};
}
try
{
await Task.WhenAll(loggingTasks);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}

}
}

/// <summary>
/// get log level from integer
/// </summary>
/// <param name="logLevel">log level as int</param>
/// <returns>log level</returns>
private async Task<LogLevel> GetLogLevel(int logLevel)
{
LogLevel retLogLevel = LogLevel.None;
try
{
retLogLevel = (LogLevel)logLevel;
}
catch (Exception ex)
{
Exception logLevelEx = new Exception("Error converting logLevel fom front-end logging. Value: " + logLevel.ToString(), ex);
await _splunkLogging.LogException(logLevelEx);
retLogLevel = LogLevel.None;
}

if (retLogLevel == LogLevel.None)
{
await _splunkLogging.LogMessage("Default log level set to none", LogLevel.Warning);
}

return retLogLevel;
}

/// <summary>
/// get log level from string
/// </summary>
/// <param name="logLevel">log level</param>
/// <returns>log level</returns>
private async Task<LogLevel> GetLogLevel(string logLevel)
{
LogLevel retLogLevel = LogLevel.None;

try
{
switch (logLevel.ToLower())
{
case "trace":
retLogLevel = LogLevel.Trace;
break;
case "debug":
retLogLevel = LogLevel.Debug;
break;
case "information":
retLogLevel = LogLevel.Information;
break;
case "warning":
retLogLevel = LogLevel.Warning;
break;
case "error":
retLogLevel = LogLevel.Error;
break;
case "critical":
retLogLevel = LogLevel.Critical;
break;
default:
retLogLevel = LogLevel.None;
break;
}
}
catch (Exception ex)
{
Exception logLevelEx = new Exception("Error converting logLevel in config file", ex);
await _splunkLogging.LogException(logLevelEx);
retLogLevel = LogLevel.None;
}

if (retLogLevel == LogLevel.None)
{
await _splunkLogging.LogMessage("Default log level set to none");
}

return retLogLevel;
}
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.