Exemple #1
0
 protected virtual void Dispose(FileStreamWrapperBase wrapper)
 {
     wrapper.Callback -= OnFileStreamAction;
     if (FileStreams.ContainsKey(wrapper.FilePath))
     {
         FileStreams.Remove(wrapper.FilePath);
     }
     wrapper.Dispose();
 }
Exemple #2
0
        public void LoadFromFile(string filePath, EventHandler <FileLoggerCallbackArgs> callback)
        {
            try
            {
                if (!Settings.IsEnabled)
                {
                    const string errMsg =
                        "reading from log file is aborted. Logger is disabled.\r\nTo enable logger set 'Settings.IsEnabled = true'.";
#if UNITY_3D || UNITY3D
                    UnityEngine.Debug.LogWarning(errMsg);
#else
                    Debug.WriteLine(errMsg);
#endif
                    return;
                }

                ArgumentValidator.AssertNotNullOrEmpty(filePath, "filePath");

                if (!File.Exists(filePath))
                {
                    throw new FileNotFoundException(filePath);
                }
                if (FileStreams.ContainsKey(filePath))
                {
                    throw new OperationCanceledException("File with path '" + filePath + "' is in process.");
                }

                var wrapper = new FileStreamReader(filePath, callback)
                {
                    IsFileCompressionEnabled = Settings.UseGzipCompression
                };
                wrapper.Callback += OnFileStreamAction;
                FileStreams.Add(filePath, wrapper);
                wrapper.LoadFromFile();
            }
            catch (Exception e)
            {
                FileStreamWrapperBase.InvokeFileActionEvent(callback, null, filePath, null, null, FileLoggerAction.Read,
                                                            FileLoggerResult.Error, e);

                if (callback == null)
                {
                    throw;
                }
            }
        }
Exemple #3
0
        public virtual void SaveToFile(string text, EventHandler <FileLoggerCallbackArgs> callback)
        {
            try
            {
                if (!Settings.IsEnabled)
                {
                    const string errMsg =
                        "Writing to log file is aborted. Logger is disabled.\r\nTo enable logger set 'Settings.IsEnabled = true'.";
#if UNITY_3D || UNITY3D
                    UnityEngine.Debug.LogWarning(errMsg);
#else
                    Debug.WriteLine(errMsg);
#endif
                    return;
                }

                ArgumentValidator.AssertNotNullOrEmpty(text, "text");

                if (!Directory.Exists(Settings.DirectoryPath))
                {
                    Directory.CreateDirectory(Settings.DirectoryPath);
                }

                var wrapper = GetFileStream(callback);
                wrapper.SaveToFile(text);
            }
            catch (Exception e)
            {
                FileStreamWrapperBase.InvokeFileActionEvent(callback, null, FilePath, null, null, FileLoggerAction.Write,
                                                            FileLoggerResult.Error, e);

                if (callback == null)
                {
                    throw;
                }
            }
        }