PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/DICOM/Log/DicomParserLogger.cs

https://github.com/petnet/fo-dicom
C# | 69 lines | 55 code | 14 blank | 0 comment | 0 complexity | 5144e5a7c64ccf28d0dff105857c9ba1 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Dicom.IO;
  6. using NLog;
  7. using Dicom.IO.Buffer;
  8. using Dicom.IO.Reader;
  9. namespace Dicom.Log {
  10. public class DicomParserLogger : IDicomReaderObserver {
  11. private Logger _log;
  12. private LogLevel _level;
  13. private int _depth;
  14. private string _pad;
  15. public DicomParserLogger(Logger log, LogLevel level) {
  16. _log = log;
  17. _level = level;
  18. _depth = 0;
  19. _pad = String.Empty;
  20. }
  21. public void OnElement(IByteSource source, DicomTag tag, DicomVR vr, IByteBuffer data) {
  22. _log.Log(_level, "{0:x8}: {1}{2} {3} {4} [{5}]", source.Marker, _pad, tag, vr.Code, tag.DictionaryEntry.Name, data.Size);
  23. }
  24. public void OnBeginSequence(IByteSource source, DicomTag tag, uint length) {
  25. _log.Log(_level, "{0:x8}: {1}{2} SQ {3}", source.Marker, _pad, tag, tag.DictionaryEntry.Name, length);
  26. IncreaseDepth();
  27. }
  28. public void OnBeginSequenceItem(IByteSource source, uint length) {
  29. _log.Log(_level, "{0:x8}: {1}Item:", source.Marker, _pad);
  30. IncreaseDepth();
  31. }
  32. public void OnEndSequenceItem() {
  33. DecreaseDepth();
  34. }
  35. public void OnEndSequence() {
  36. DecreaseDepth();
  37. }
  38. public void OnBeginFragmentSequence(IByteSource source, DicomTag tag, DicomVR vr) {
  39. _log.Log(_level, "{0:x8}: {1}{2} {3} {4}", source.Marker, _pad, tag, vr.Code, tag.DictionaryEntry.Name);
  40. IncreaseDepth();
  41. }
  42. public void OnFragmentSequenceItem(IByteSource source, IByteBuffer data) {
  43. _log.Log(_level, "{0:x8}: {1}Fragment [{2}]", source.Marker, _pad, data.Size);
  44. }
  45. public void OnEndFragmentSequence() {
  46. DecreaseDepth();
  47. }
  48. private void IncreaseDepth() {
  49. _depth++;
  50. }
  51. private void DecreaseDepth() {
  52. _depth--;
  53. }
  54. }
  55. }