Example #1
0
        async public Task <string> LogFilename(string mapName, loggingMethod loggingMethod, bool createDir = false)
        {
            if (!String.IsNullOrWhiteSpace(_mapServerService.Options.LoggingRootPath))
            {
                mapName = mapName?.ToLower() ?? String.Empty;

                var dir = new DirectoryInfo(_mapServerService.Options.LoggingRootPath + "/" + mapName);
                if (createDir && !dir.Exists)
                {
                    dir.Create();
                }

                var mapService = String.IsNullOrWhiteSpace(mapName) ? null : _mapServerService.MapServices.Where(s => s.Fullname?.ToLower() == mapName).FirstOrDefault();

                var ticks = (mapService != null && mapService.RunningSinceUtc.HasValue) ? mapService.RunningSinceUtc.Value.Ticks : DateTime.UtcNow.Ticks;

                if (mapService != null)
                {
                    if (!mapService.RunningSinceUtc.HasValue)
                    {
                        var settings = await mapService?.GetSettingsAsync();

                        if (settings != null)
                        {
                            ticks = settings.RefreshService.Ticks;
                        }
                    }
                    else
                    {
                        ticks = mapService.RunningSinceUtc.Value.Ticks;
                    }
                }

                string fileName = $"{ loggingMethod.ToString() }-{ ticks.ToString().PadLeft(21, '0') }.log";

                return(dir + "/" + fileName);
            }

            return(String.Empty);
        }
Example #2
0
        async public Task LogAsync(string mapName, loggingMethod loggingMethod, string message)
        {
            try
            {
                mapName = mapName?.ToLower() ?? String.Empty;

                if (!String.IsNullOrWhiteSpace(_mapServerService.Options.LoggingRootPath))
                {
                    string fileName = await LogFilename(mapName, loggingMethod, true);

                    await File.AppendAllLinesAsync(fileName,
                                                   new string[]
                    {
                        DateTime.UtcNow.ToShortDateString() + " " + DateTime.UtcNow.ToLongTimeString() + " (UTC) " + message,
                        "-"
                    });
                }
                else
                {
                    Console.WriteLine(DateTime.UtcNow.ToShortDateString() + " " + DateTime.UtcNow.ToLongTimeString() + " (UTC) " + loggingMethod.ToString() + ": " + message);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Logging error: " + ex.Message);
            }
        }
Example #3
0
 static public void Log(loggingMethod loggingMethod, string message)
 {
     Console.WriteLine(DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString() + " " + loggingMethod.ToString() + ": " + message);
 }