Beispiel #1
0
        public CloudFileDirectory GetCloudFileDirectoryByEvent(LogEvent logEvent)
        {
            var azureConfig = _azureConfigContainer.Get(logEvent);

            if (azureConfig == null)
            {
                return(null);
            }

            var storageAccount = CloudStorageAccount.Parse(azureConfig.ConnectionString);

            CloudFileClient fileClient = storageAccount.CreateCloudFileClient();

            CloudFileShare share = fileClient.GetShareReference(azureConfig.FileShare);

            if (!share.Exists())
            {
                throw new StorageException($"{azureConfig.FileDirectory} not found.");
            }

            CloudFileDirectory rootDir = share.GetRootDirectoryReference();

            CloudFileDirectory cloudFileDirectory = rootDir.GetDirectoryReference(azureConfig.FileDirectory);

            return(cloudFileDirectory);
        }
Beispiel #2
0
        public void Log(LogReceivedEventArgs logReceivedEvent)
        {
            var azureFileDirectory = _azureService.GetCloudFileDirectoryByEvent(logReceivedEvent.LogInfo.LogEvent);

            if (azureFileDirectory == null)
            {
                return;
            }

            var fileConfig = _fileConfigContainer.Get(logReceivedEvent.LogInfo.LogEvent);

            if (fileConfig == null)
            {
                return;
            }

            CloudFile file = azureFileDirectory.GetFileReference(fileConfig.FileName);

            string filePath = Path.Combine(fileConfig.LogPath, fileConfig.FileName);

            if (File.Exists(filePath))
            {
                throw new FileNotFoundException($"{filePath} not found.");
            }

            using (var fileStream = File.OpenRead(filePath))
            {
                file.UploadFromStream(fileStream);
            }
        }
Beispiel #3
0
        public void Log(LogReceivedEventArgs logReceivedEvent)
        {
            IFileConfig currentConfig = _fileConfigContainer.Get(logReceivedEvent.LogInfo.LogEvent);

            if (currentConfig == null)
            {
                throw new ConfigurationErrorsException($"{System.Enum.GetName(typeof(LogEvent), logReceivedEvent.LogInfo.LogEvent)} is not supported");
            }

            _fileAnalyzer.FileName      = currentConfig.FileName;
            _fileAnalyzer.LogPath       = currentConfig.LogPath;
            _fileAnalyzer.FileSizeLimit = currentConfig.FileSizeLimit;

            string logFile = _fileAnalyzer.GetLogFile();

            string message = _logMessageCreator.CreateMessage(logReceivedEvent.LogInfo);

            File.AppendAllText(logFile, message + System.Environment.NewLine);
        }