From 0f8b3c634708ce8e7b2e2ae6fed87b6b943b5bca Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Thu, 13 Dec 2018 14:18:25 +0100 Subject: Use Microsoft.Extensions.Logging abstraction --- Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs | 52 +++++++++++++------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs') diff --git a/Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs b/Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs index 620d3bae9..e6986ddcb 100644 --- a/Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs +++ b/Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs @@ -4,7 +4,7 @@ using System.Threading; using System.Threading.Tasks; using MediaBrowser.Model.Diagnostics; using MediaBrowser.Model.IO; -using MediaBrowser.Model.Logging; +using Microsoft.Extensions.Logging; using MediaBrowser.Model.System; using System.Runtime.InteropServices; @@ -20,7 +20,7 @@ namespace IsoMounter private readonly IEnvironmentInfo EnvironmentInfo; private readonly bool ExecutablesAvailable; private readonly IFileSystem FileSystem; - private readonly ILogger Logger; + private readonly ILogger _logger; private readonly string MountCommand; private readonly string MountPointRoot; private readonly IProcessFactory ProcessFactory; @@ -36,24 +36,24 @@ namespace IsoMounter EnvironmentInfo = environment; FileSystem = fileSystem; - Logger = logger; + _logger = logger; ProcessFactory = processFactory; MountPointRoot = FileSystem.DirectorySeparatorChar + "tmp" + FileSystem.DirectorySeparatorChar + "Emby"; - Logger.Debug( + _logger.LogDebug( "[{0}] System PATH is currently set to [{1}].", Name, EnvironmentInfo.GetEnvironmentVariable("PATH") ?? "" ); - Logger.Debug( + _logger.LogDebug( "[{0}] System path separator is [{1}].", Name, EnvironmentInfo.PathSeparator ); - Logger.Debug( + _logger.LogDebug( "[{0}] Mount point root is [{1}].", Name, MountPointRoot @@ -65,7 +65,7 @@ namespace IsoMounter SudoCommand = GetFullPathForExecutable("sudo"); - Logger.Info( + _logger.LogInformation( "[{0}] Using version of [sudo] located at [{1}].", Name, SudoCommand @@ -73,7 +73,7 @@ namespace IsoMounter MountCommand = GetFullPathForExecutable("mount"); - Logger.Info( + _logger.LogInformation( "[{0}] Using version of [mount] located at [{1}].", Name, MountCommand @@ -81,7 +81,7 @@ namespace IsoMounter UmountCommand = GetFullPathForExecutable("umount"); - Logger.Info( + _logger.LogInformation( "[{0}] Using version of [umount] located at [{1}].", Name, UmountCommand @@ -119,7 +119,7 @@ namespace IsoMounter { if (EnvironmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Linux) { - Logger.Info( + _logger.LogInformation( "[{0}] Checking we can attempt to mount [{1}], Extension = [{2}], Operating System = [{3}], Executables Available = [{4}].", Name, path, @@ -182,7 +182,7 @@ namespace IsoMounter return; } - Logger.Info( + _logger.LogInformation( "[{0}] Disposing [{1}].", Name, disposing.ToString() @@ -230,7 +230,7 @@ namespace IsoMounter var uid = getuid(); - Logger.Debug( + _logger.LogDebug( "[{0}] Our current UID is [{1}], GetUserId() returned [{2}].", Name, uid.ToString(), @@ -267,13 +267,13 @@ namespace IsoMounter //StreamReader outputReader = process.StandardOutput.; //StreamReader errorReader = process.StandardError; - Logger.Debug( + _logger.LogDebug( "[{0}] Standard output from process is [{1}].", Name, process.StandardOutput.ReadToEnd() ); - Logger.Debug( + _logger.LogDebug( "[{0}] Standard error from process is [{1}].", Name, process.StandardError.ReadToEnd() @@ -283,7 +283,7 @@ namespace IsoMounter processFailed = true; - Logger.Debug( + _logger.LogDebug( "[{0}] Unhandled exception executing command, exception is [{1}].", Name, ex.Message @@ -308,13 +308,13 @@ namespace IsoMounter if (!string.IsNullOrEmpty(isoPath)) { - Logger.Info( + _logger.LogInformation( "[{0}] Attempting to mount [{1}].", Name, isoPath ); - Logger.Debug( + _logger.LogDebug( "[{0}] ISO will be mounted at [{1}].", Name, mountPoint @@ -342,7 +342,7 @@ namespace IsoMounter cmdArguments = string.Format("\"{0}\" \"{1}\" \"{2}\"", MountCommand, isoPath, mountPoint); } - Logger.Debug( + _logger.LogDebug( "[{0}] Mount command [{1}], mount arguments [{2}].", Name, cmdFilename, @@ -351,7 +351,7 @@ namespace IsoMounter if (ExecuteCommand(cmdFilename, cmdArguments)) { - Logger.Info( + _logger.LogInformation( "[{0}] ISO mount completed successfully.", Name ); @@ -360,7 +360,7 @@ namespace IsoMounter } else { - Logger.Info( + _logger.LogInformation( "[{0}] ISO mount completed with errors.", Name ); @@ -371,7 +371,7 @@ namespace IsoMounter } catch (Exception ex) { - Logger.Info( + _logger.LogInformation( "[{0}] Unhandled exception removing mount point, exception is [{1}].", Name, ex.Message @@ -395,7 +395,7 @@ namespace IsoMounter if (mount != null) { - Logger.Info( + _logger.LogInformation( "[{0}] Attempting to unmount ISO [{1}] mounted on [{2}].", Name, mount.IsoPath, @@ -416,7 +416,7 @@ namespace IsoMounter cmdArguments = string.Format("\"{0}\" \"{1}\"", UmountCommand, mount.MountedPath); } - Logger.Debug( + _logger.LogDebug( "[{0}] Umount command [{1}], umount arguments [{2}].", Name, cmdFilename, @@ -425,14 +425,14 @@ namespace IsoMounter if (ExecuteCommand(cmdFilename, cmdArguments)) { - Logger.Info( + _logger.LogInformation( "[{0}] ISO unmount completed successfully.", Name ); } else { - Logger.Info( + _logger.LogInformation( "[{0}] ISO unmount completed with errors.", Name ); @@ -445,7 +445,7 @@ namespace IsoMounter } catch (Exception ex) { - Logger.Info( + _logger.LogInformation( "[{0}] Unhandled exception removing mount point, exception is [{1}].", Name, ex.Message -- cgit v1.2.3 From 79d18cf5a5fde7594eb17247f920a54d8978a81c Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Thu, 20 Dec 2018 13:39:58 +0100 Subject: Clean up some catch statements --- Emby.Dlna/Didl/DidlBuilder.cs | 4 +- Emby.Dlna/DlnaManager.cs | 4 +- Emby.Dlna/PlayTo/Device.cs | 4 +- Emby.Drawing.ImageMagick/ImageMagickEncoder.cs | 4 +- Emby.Drawing/ImageProcessor.cs | 10 +-- Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs | 72 +++++++++------------- Emby.Server.Implementations/ApplicationHost.cs | 2 +- Emby.Server.Implementations/Dto/DtoService.cs | 2 +- .../EntryPoints/ExternalPortForwarding.cs | 1 + Emby.Server.Implementations/IO/SharpCifs/Config.cs | 2 +- .../IO/SharpCifs/Dcerpc/DcerpcHandle.cs | 2 +- .../IO/SharpCifs/Netbios/Name.cs | 2 +- .../IO/SharpCifs/Netbios/NameServiceClient.cs | 8 ++- .../IO/SharpCifs/Smb/NtlmContext.cs | 2 +- 14 files changed, 56 insertions(+), 63 deletions(-) (limited to 'Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs') diff --git a/Emby.Dlna/Didl/DidlBuilder.cs b/Emby.Dlna/Didl/DidlBuilder.cs index 6de35b842..7af48ae17 100644 --- a/Emby.Dlna/Didl/DidlBuilder.cs +++ b/Emby.Dlna/Didl/DidlBuilder.cs @@ -1070,9 +1070,9 @@ namespace Emby.Dlna.Didl { tag = _imageProcessor.GetImageCacheTag(item, type); } - catch + catch (Exception ex) { - + _logger.LogError(ex, "Error getting image cache tag"); } int? width = imageInfo.Width; diff --git a/Emby.Dlna/DlnaManager.cs b/Emby.Dlna/DlnaManager.cs index eae4f3271..48a33757b 100644 --- a/Emby.Dlna/DlnaManager.cs +++ b/Emby.Dlna/DlnaManager.cs @@ -198,7 +198,7 @@ namespace Emby.Dlna } catch (ArgumentException ex) { - _logger.LogError(ex, "Error evaluating regex pattern {0}", pattern); + _logger.LogError(ex, "Error evaluating regex pattern {Pattern}", pattern); return false; } } @@ -324,7 +324,7 @@ namespace Emby.Dlna } catch (Exception ex) { - _logger.LogError(ex, "Error parsing profile file: {0}", path); + _logger.LogError(ex, "Error parsing profile file: {Path}", path); return null; } diff --git a/Emby.Dlna/PlayTo/Device.cs b/Emby.Dlna/PlayTo/Device.cs index a1df90ec0..13bed6b2f 100644 --- a/Emby.Dlna/PlayTo/Device.cs +++ b/Emby.Dlna/PlayTo/Device.cs @@ -140,7 +140,7 @@ namespace Emby.Dlna.PlayTo } catch (Exception ex) { - _logger.LogError(ex, "Error updating device volume info for {0}", Properties.Name); + _logger.LogError(ex, "Error updating device volume info for {DeviceName}", Properties.Name); } } @@ -507,7 +507,7 @@ namespace Emby.Dlna.PlayTo if (_disposed) return; - //_logger.LogError(ex, "Error updating device info for {0}", Properties.Name); + _logger.LogError(ex, "Error updating device info for {DeviceName}", Properties.Name); _connectFailureCount++; diff --git a/Emby.Drawing.ImageMagick/ImageMagickEncoder.cs b/Emby.Drawing.ImageMagick/ImageMagickEncoder.cs index 6aac77cf4..5de8ac383 100644 --- a/Emby.Drawing.ImageMagick/ImageMagickEncoder.cs +++ b/Emby.Drawing.ImageMagick/ImageMagickEncoder.cs @@ -101,9 +101,9 @@ namespace Emby.Drawing.ImageMagick wand.SaveImage(tmpPath); } } - catch + catch (Exception ex) { - //_logger.LogError(ex, "Error loading webp: "); + _logger.LogError(ex, "Error loading webp"); _webpAvailable = false; } } diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs index c417f3785..6a67be56d 100644 --- a/Emby.Drawing/ImageProcessor.cs +++ b/Emby.Drawing/ImageProcessor.cs @@ -646,16 +646,16 @@ namespace Emby.Drawing var cacheGuid = GetImageCacheTag(item, image, enhancers); // Enhance if we have enhancers - var ehnancedImageInfo = await GetEnhancedImageInternal(originalImagePath, item, imageType, imageIndex, enhancers, cacheGuid, cancellationToken).ConfigureAwait(false); + var enhancedImageInfo = await GetEnhancedImageInternal(originalImagePath, item, imageType, imageIndex, enhancers, cacheGuid, cancellationToken).ConfigureAwait(false); - var ehnancedImagePath = ehnancedImageInfo.Item1; + var enhancedImagePath = enhancedImageInfo.Item1; // If the path changed update dateModified - if (!string.Equals(ehnancedImagePath, originalImagePath, StringComparison.OrdinalIgnoreCase)) + if (!string.Equals(enhancedImagePath, originalImagePath, StringComparison.OrdinalIgnoreCase)) { - var treatmentRequiresTransparency = ehnancedImageInfo.Item2; + var treatmentRequiresTransparency = enhancedImageInfo.Item2; - return new ValueTuple(ehnancedImagePath, _fileSystem.GetLastWriteTimeUtc(ehnancedImagePath), treatmentRequiresTransparency); + return new ValueTuple(enhancedImagePath, _fileSystem.GetLastWriteTimeUtc(enhancedImagePath), treatmentRequiresTransparency); } } catch (Exception ex) diff --git a/Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs b/Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs index e6986ddcb..faaed482a 100644 --- a/Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs +++ b/Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs @@ -260,35 +260,29 @@ namespace IsoMounter } ); - try { - + try + { process.Start(); //StreamReader outputReader = process.StandardOutput.; //StreamReader errorReader = process.StandardError; _logger.LogDebug( - "[{0}] Standard output from process is [{1}].", + "[{Name}] Standard output from process is [{Error}].", Name, process.StandardOutput.ReadToEnd() ); _logger.LogDebug( - "[{0}] Standard error from process is [{1}].", + "[{Name}] Standard error from process is [{Error}].", Name, process.StandardError.ReadToEnd() ); - - } catch (Exception ex) { - + } + catch (Exception ex) + { processFailed = true; - - _logger.LogDebug( - "[{0}] Unhandled exception executing command, exception is [{1}].", - Name, - ex.Message - ); - + _logger.LogDebug(ex, "[{Name}] Unhandled exception executing command.", Name); } if (!processFailed && process.ExitCode == 0) { @@ -309,13 +303,13 @@ namespace IsoMounter if (!string.IsNullOrEmpty(isoPath)) { _logger.LogInformation( - "[{0}] Attempting to mount [{1}].", + "[{Name}] Attempting to mount [{Path}].", Name, isoPath ); _logger.LogDebug( - "[{0}] ISO will be mounted at [{1}].", + "[{Name}] ISO will be mounted at [{Path}].", Name, mountPoint ); @@ -326,11 +320,16 @@ namespace IsoMounter } - try { + try + { FileSystem.CreateDirectory(mountPoint); - } catch (UnauthorizedAccessException) { + } + catch (UnauthorizedAccessException) + { throw new IOException("Unable to create mount point(Permission denied) for " + isoPath); - } catch (Exception) { + } + catch (Exception) + { throw new IOException("Unable to create mount point for " + isoPath); } @@ -365,18 +364,13 @@ namespace IsoMounter Name ); - try { - + try + { FileSystem.DeleteDirectory(mountPoint, false); - - } catch (Exception ex) { - - _logger.LogInformation( - "[{0}] Unhandled exception removing mount point, exception is [{1}].", - Name, - ex.Message - ); - + } + catch (Exception ex) + { + _logger.LogInformation(ex, "[{Name}] Unhandled exception removing mount point.", Name); } mountedISO = null; @@ -439,20 +433,14 @@ namespace IsoMounter } - try { - + try + { FileSystem.DeleteDirectory(mount.MountedPath, false); - - } catch (Exception ex) { - - _logger.LogInformation( - "[{0}] Unhandled exception removing mount point, exception is [{1}].", - Name, - ex.Message - ); - } - + catch (Exception ex) + { + _logger.LogInformation(ex, "[{Name}] Unhandled exception removing mount point.", Name); + } } #endregion diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 888635c9d..d4b740d71 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -2214,7 +2214,7 @@ namespace Emby.Server.Implementations } catch (Exception ex) { - Logger.LogDebug("Ping test result to {0}. Success: {1} {2}", apiUrl, false, ex.Message); + Logger.LogDebug(ex, "Ping test result to {0}. Success: {1}", apiUrl, false); _validAddressResults.AddOrUpdate(apiUrl, false, (k, v) => false); return false; diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs index e8d06ec00..7871d3fb3 100644 --- a/Emby.Server.Implementations/Dto/DtoService.cs +++ b/Emby.Server.Implementations/Dto/DtoService.cs @@ -619,7 +619,7 @@ namespace Emby.Server.Implementations.Dto } catch (Exception ex) { - _logger.LogError(ex, "Error getting person {0}", c); + _logger.LogError(ex, "Error getting person {Name}", c); return null; } diff --git a/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs b/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs index a95e21e1c..6cd867921 100644 --- a/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs +++ b/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs @@ -166,6 +166,7 @@ namespace Emby.Server.Implementations.EntryPoints } catch (Exception ex) { + _logger.LogError(ex, "Error"); return; } diff --git a/Emby.Server.Implementations/IO/SharpCifs/Config.cs b/Emby.Server.Implementations/IO/SharpCifs/Config.cs index 3fd0e5bd6..324a9c494 100644 --- a/Emby.Server.Implementations/IO/SharpCifs/Config.cs +++ b/Emby.Server.Implementations/IO/SharpCifs/Config.cs @@ -89,7 +89,7 @@ namespace SharpCifs { Runtime.GetBytesForString(string.Empty, DefaultOemEncoding); } - catch (Exception ex) + catch (Exception) { if (_log.Level >= 2) { diff --git a/Emby.Server.Implementations/IO/SharpCifs/Dcerpc/DcerpcHandle.cs b/Emby.Server.Implementations/IO/SharpCifs/Dcerpc/DcerpcHandle.cs index 786b0ac12..e82af2b0c 100644 --- a/Emby.Server.Implementations/IO/SharpCifs/Dcerpc/DcerpcHandle.cs +++ b/Emby.Server.Implementations/IO/SharpCifs/Dcerpc/DcerpcHandle.cs @@ -153,7 +153,7 @@ namespace SharpCifs.Dcerpc DcerpcMessage bind = new DcerpcBind(Binding, this); Sendrecv(bind); } - catch (IOException ioe) + catch (IOException) { State = 0; throw; diff --git a/Emby.Server.Implementations/IO/SharpCifs/Netbios/Name.cs b/Emby.Server.Implementations/IO/SharpCifs/Netbios/Name.cs index 6c37d57a4..15ae494be 100644 --- a/Emby.Server.Implementations/IO/SharpCifs/Netbios/Name.cs +++ b/Emby.Server.Implementations/IO/SharpCifs/Netbios/Name.cs @@ -130,7 +130,7 @@ namespace SharpCifs.Netbios { name = Runtime.GetStringForBytes(tmp, 0, length).Trim(); } - catch (Exception ex) + catch (Exception) { } diff --git a/Emby.Server.Implementations/IO/SharpCifs/Netbios/NameServiceClient.cs b/Emby.Server.Implementations/IO/SharpCifs/Netbios/NameServiceClient.cs index 01700e64a..0d7840a64 100644 --- a/Emby.Server.Implementations/IO/SharpCifs/Netbios/NameServiceClient.cs +++ b/Emby.Server.Implementations/IO/SharpCifs/Netbios/NameServiceClient.cs @@ -117,8 +117,9 @@ namespace SharpCifs.Netbios { Baddr = Config.GetInetAddress("jcifs.netbios.baddr", Extensions.GetAddressByName("255.255.255.255")); } - catch (Exception ex) + catch (Exception) { + } _sndBuf = new byte[SndBufSize]; @@ -302,7 +303,10 @@ namespace SharpCifs.Netbios } } - catch (TimeoutException) { } + catch (TimeoutException) + { + + } catch (Exception ex) { if (_log.Level > 2) diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmContext.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmContext.cs index 44266f974..aa52ee1db 100644 --- a/Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmContext.cs +++ b/Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmContext.cs @@ -192,7 +192,7 @@ namespace SharpCifs.Smb catch (Exception e) { throw new SmbException(e.Message, e); - } + } } default: -- cgit v1.2.3