Exemple #1
0
        public ILogEntry CreateLogEntry(LogOutputType outputType, Priority priority)
        {
            if (_retrieveUser == null)
            {
                throw new NotImplementedException(String.Format("Implementation for member '{0}' is required",
                                                                "RetrieveUser"));
            }

            if (_retrieveSessionId == null)
            {
                throw new NotImplementedException(String.Format("Implementation for member '{0}' is required",
                                                                "RetrieveSessionId"));
            }

            if (_retrieveBusinessTransactionId == null)
            {
                throw new NotImplementedException(String.Format("Implementation for member '{0}' is required",
                                                                "RetrieveBusinessTransactionId"));
            }

            ILogEntry log = new LogEntry(outputType,
                                         TimeZoneInfo.Local,
                                         DateTime.Now,
                                         _retrieveUser(),
                                         _retrieveSessionId(),
                                         _retrieveBusinessTransactionId(),
                                         priority
                                         )
            {
                Status     = Status.None,
                Parameters = new Dictionary <string, object>()
            };

            return(log);
        }
Exemple #2
0
 /// <summary>
 /// Creates a new instance of the <see cref="ConsoleLogger"/> class with a specified output type.
 /// </summary>
 /// <param name="type"> The output type of the logger. </param>
 /// <param name="suppressConsoleResize"> Whether to suppress the console buffer from getting resized. </param>
 public ConsoleLogger(LogOutputType type = LogOutputType.ThreadTime, bool suppressConsoleResize = false)
 {
     Log.AddLogger(this);
     this.type = type;
     if (hndlr == null)
     {
         AddConsoleHandle(hndlr += OnConsoleExit);
     }
     if (!suppressConsoleResize)
     {
         BufferHeight = ExtraMath.Clamp(BufferHeight << 2, MIN_SIZE, MAX_SIZE);
         BufferWidth  = ExtraMath.Clamp(BufferWidth << 2, MIN_SIZE, MAX_SIZE);
     }
 }
Exemple #3
0
        public void EmitLog(bool retainParameters, LogOutputType outputType, Priority priority, Status status)
        {
            ILogEntry entry = CreateLogEntry(outputType, priority, status);

            entry.Status     = status;
            entry.Parameters = CloneParameters(_parameterList);

            EmitLog(entry);

            if (!retainParameters)
            {
                _parameterList.Clear();
            }
        }
Exemple #4
0
        public ILogEntry CreateLogEntry(LogOutputType outputType, Priority priority, Status status)
        {
            ILogEntry entry = _manager.CreateLogEntry(outputType, priority);

            entry.System      = System;
            entry.Application = Application;
            entry.Component   = Component;

            entry.Event = Event;

            entry.Status = status;

            return(entry);
        }
Exemple #5
0
        public LogEntry(LogOutputType outputType,
                        TimeZoneInfo timeZoneInfo, DateTime occurence,
                        string user, string sessionId, string transactionId,
                        Priority priority)
        {
            _id = Guid.NewGuid().ToString();

            _outputType    = outputType;
            _timeZoneInfo  = timeZoneInfo;
            _occurence     = occurence;
            _user          = user;
            _sessionId     = sessionId;
            _transactionId = transactionId;
            _priority      = priority;
        }
Exemple #6
0
        /// <summary>
        /// Gets the header line that should be printed with the specified output type.
        /// </summary>
        /// <param name="type"> The way the header should be represented. </param>
        /// <returns> A string containing the header in the specified output format. </returns>
        public string GetLogHeaderLine(LogOutputType type)
        {
            switch (type)
            {
            case LogOutputType.Brief:
                return($"[{PId}][{Type}][{Tag}]");

            case LogOutputType.Process:
                return($"[{PId}]");

            case LogOutputType.Tag:
                return($"[{Type}][{Tag}]");

            case LogOutputType.Time:
                return($"[{GetTimeStamp()}][{PId:00000}][{Type}][{Tag}]");

            case LogOutputType.ThreadTime:
                return($"[{GetTimeStamp()}][{PId:00000}/{TId:00}][{Type}][{Tag}]");

            default:
                return(string.Empty);
            }
        }
Exemple #7
0
 public void EmitLog(LogOutputType outputType, Priority priority, Status status)
 {
     EmitLog(false, outputType, priority, status);
 }
Exemple #8
0
 public ILogEntry CreateLogEntry(LogOutputType outputType, Priority priority)
 {
     return(CreateLogEntry(outputType, priority, Status.None));
 }
Exemple #9
0
        static void Main(string[] args)
        {
            CompilerLog compilerLog = new CompilerLog();

            compilerLog.Message("Compiler starting");
            LogOutputType outputType = args.Any(x => x.ToLower() == "--jsonoutput")
                ? LogOutputType.Json
                : LogOutputType.Console;

            CompileTargetEnum target = args.Any(x => x.ToLower() == "--netcore21") ? CompileTargetEnum.NETCore21 : CompileTargetEnum.NETStandard20;
            string            outputBinaryDirectory = String.Empty;

            compilerLog.Message($"Targeting {target}");

            if (args.Length == 0)
            {
                compilerLog.Error("Must specify the assembly file to build the functions from");
            }
            else
            {
                try
                {
                    string inputAssemblyFile = args[0];
                    compilerLog.Message($"Loading assembly {inputAssemblyFile}");
                    // TODO: convert the input to an absolute path if necessary
                    Assembly assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(inputAssemblyFile);
                    outputBinaryDirectory = Path.GetDirectoryName(assembly.Location);

                    // Not sure why the AssemblyLoadContext doesn't deal with the below. I thought it did. Clearly not.
                    // TODO: Have a chat with someone who knows a bit more about this.
                    AssemblyLoadContext.Default.Resolving += (context, name) =>
                    {
                        string path = Path.Combine(outputBinaryDirectory, $"{name.Name}.dll");
                        //string path = $"{outputBinaryDirectory}\\{name.Name}.dll";
                        if (File.Exists(path))
                        {
                            Assembly referencedAssembly = context.LoadFromAssemblyPath(path);
                            return(referencedAssembly);
                        }
                        return(null);
                    };

                    FunctionCompiler compiler = new FunctionCompiler(assembly, outputBinaryDirectory, target, compilerLog);
                    compiler.Compile();
                }
                catch (Exception e)
                {
                    compilerLog.Error($"Unexpected error: {e.Message}");
                }
            }
            compilerLog.Message("Compilation complete");

            if (compilerLog.HasItems)
            {
                if (string.IsNullOrWhiteSpace(outputBinaryDirectory) && outputType == LogOutputType.Json)
                {
                    compilerLog.Warning("Cannot write errors to output file as no output directory can be found, likely a missing assembly");
                    outputType = LogOutputType.Console;
                }

                if (outputType == LogOutputType.Console)
                {
                    System.Console.WriteLine(compilerLog.ToConsole());
                }
                else
                {
                    string outputPath = Path.Combine(outputBinaryDirectory, "__fm__errors.json");
                    File.WriteAllText(outputPath, compilerLog.ToJson());
                }
            }
        }
Exemple #10
0
 public static bool HasFlag(this LogOutputType thisEnum, LogOutputType checkFlag)
 {
     return((thisEnum & checkFlag) == checkFlag);
 }
Exemple #11
0
 /// <summary>
 /// Gets the line that should be printed with the specified output type.
 /// </summary>
 /// <param name="type"> The way the header should be represented. </param>
 /// <returns> A string containing the header and the message in the specified output format. </returns>
 public string GetLogLine(LogOutputType type)
 {
     return(GetLogHeaderLine(type) + $": {Message}");
 }